home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 1 / PC Actual CD 01.iso / share / dos / progr / micro_c.arj / MC.DOC < prev    next >
Encoding:
Text File  |  1993-10-05  |  171.6 KB  |  3,602 lines

  1.           
  2.           
  3.           
  4.           
  5.           
  6.           
  7.           
  8.           
  9.           
  10.           ===========================================================
  11.                 DDDDD           DDDDD               SSSS
  12.                  D   Dunfield    D   D             S
  13.                  D   D           D   Development    SSSS 
  14.                  D   D           D   D                  Systems
  15.                 DDDDD           DDDDD               SSSS
  16.           ===========================================================
  17.           MM   MM  IIIIIII    CCCC   RRRRRR     OOO             CCCC
  18.           M M M M     I      C    C  R     R   O   O           C    C
  19.           M  M  M     I     C        R     R  O     O         C
  20.           M     M     I     C        RRRRRR   O     O  -----  C
  21.           M     M     I     C        R   R    O     O         C
  22.           M     M     I      C    C  R    R    O   O           C    C
  23.           M     M  IIIIIII    CCCC   R     R    OOO             CCCC
  24.           ===========================================================
  25.     
  26.     
  27.     
  28.     
  29.     
  30.                              A compact 'C' compiler
  31.                                       for
  32.                                  Small Systems.
  33.     
  34.     
  35.                                 Technical Manual
  36.     
  37.     
  38.     
  39.     
  40.     
  41.                                   Release 3.01
  42.     
  43.                                Revised 18-Sep-93
  44.     
  45.     
  46.     
  47.     
  48.     
  49.     
  50.     
  51.     
  52.     
  53.     
  54.     
  55.     
  56.                        Copyright 1988-1993 Dave Dunfield
  57.                               All rights reserved
  58.     MICRO-C                                                          Page: 1
  59.  
  60.  
  61.     1. INTRODUCTION
  62.     
  63.           DDS MICRO-C is a compact, portable compiler for the  'C'  language
  64.        which is suitable for implementation on small 8 or  16  bit  computer
  65.        systems. It may be used as a  resident  or  cross  compiler,  and  is
  66.        capable of generating ROMable code. It is distributed in source form,
  67.        and thus provides a learning tool for those wishing  to  examine  the
  68.        internals of a working compiler.
  69.     
  70.           The main goal in the development of MICRO-C, has been to provide a
  71.        reasonably powerful language  which  will  be  portable  with  little
  72.        difficulty to many  target  systems.  The  'C'  language  was  chosen
  73.        because  it  was  designed  to  be  portable,  and   provides   ample
  74.        programming power. MICRO-C provides  an  alternative  to  interpreted
  75.        BASIC or assembly language  programming  which  are  often  the  only
  76.        languages available on small 8 bit systems.
  77.     
  78.           With today's focus on larger computers and workstations,  software
  79.        support for small  systems  and  micro-controller  sized  devices  is
  80.        getting both hard to find, and expensive.  MICRO-C  helps  fill  that
  81.        gap, because all files necessary to port and  maintain  the  compiler
  82.        are included on the distribution disks, allowing it to  be  moved  to
  83.        ANY system without dependance on a software vendor.
  84.     
  85.           Included in this package is a complete  IBM/PC  implementation  of
  86.        MICRO-C, with a comprehensive  library,  which  you  may  use  as  an
  87.        example installation. This implementation of  the  compiler  requires
  88.        the Microsoft MASM (or compatible) assembler.
  89.     
  90.           The MICRO-C "package" (software and documentation) is copyrighted,
  91.        and may  not  be  re-distributed  in  any  form  without  my  written
  92.        permission. If you have received the  "DEMO"  archive,  and  wish  to
  93.        obtain the entire MICRO-C package complete with source code, fill out
  94.        and send the order form contained in the "READ.ME" file,  along  with
  95.        the required payment to:
  96.     
  97.                            Dunfield Development Systems
  98.                            P.O. Box 31044
  99.                            Nepean, Ontario (Canada)
  100.                            K2B 8S8
  101.     
  102.           Please make your  cheque  or  money  order  payable  to  "Dunfield
  103.        Development Systems".
  104.     
  105.           MICRO-C is provided on an "as is" basis, with no warranty  of  any
  106.        kind. In no event shall the author be liable for any damages  arising
  107.        from its use or distribution.
  108.     MICRO-C                                                          Page: 2
  109.  
  110.  
  111.        1.1 Compiler Portability
  112.     
  113.              MICRO-C is written in standard 'C', and is capable of compiling
  114.           itself. This allows any system  with  a  'C'  compiler  (including
  115.           MICRO-C) to be used to port MICRO-C to another processor.
  116.     
  117.              The  parser  makes  very  few  assumptions  about  the   target
  118.           processor  or  operating  system  architecture,  allowing  a  code
  119.           generator  to  be  written  for  virtually   any   processor   and
  120.           environment.
  121.     
  122.              With the exception of required I/O routines (described  later),
  123.           the MICRO-C compiler uses no library functions, and relies  on  no
  124.           system services.
  125.     
  126.              Assuming that the code generator is fairly efficent,  and  that
  127.           the I/O routines and code generator are not unreasonably large,  a
  128.           full MICRO-C compiler may be implemented on systems with as little
  129.           as 32K of free ram and a single floppy disk.
  130.     
  131.        1.2 Code Portability
  132.     
  133.              With few exceptions, this compiler follows the  syntax  of  the
  134.           "standard" UNIX compiler (within  its  subset  of  the  language).
  135.           Programs written in MICRO-C should compile with few changes  under
  136.           other "standard" compilers.
  137.     
  138.           1.2.1 Unsupported Features:
  139.     
  140.                 MICRO-C does not currently support the following features of
  141.              standard 'C':
  142.     
  143.                     Long / Double / Float / Enumerated data types,
  144.                     Typedef and Bit fields.
  145.     
  146.           1.2.2 Additional Features
  147.     
  148.                 MICRO-C provides a few additional  features  which  are  not
  149.              always included in "standard" 'C' compilers:
  150.     
  151.                     Unsigned character variables, Nested comments, 16 bit
  152.                     character constants, Inline assembly code capability.
  153.     MICRO-C                                                          Page: 3
  154.  
  155.  
  156.        1.3 The compiling process
  157.     
  158.              There are five  programs  which  work  together  to  completely
  159.           compile a MICRO-C program:
  160.     
  161.              The PREPROCESSOR (MCP) takes  the  original  'C'  source  file,
  162.           performs MACRO expansion and incorporates the contents of  INCLUDE
  163.           files  to  get  a  "pure"  'C'  output  file.  A   less   powerful
  164.           pre-processor is also contained inside the COMPILER, which  allows
  165.           this step to  be  skipped  for  programs  which  use  only  simple
  166.           pre-processor functions.
  167.     
  168.              The COMPILER  (MCC)  reads  a  file  containing  a  'C'  source
  169.           program, and translates it into an  equivalent  assembly  language
  170.           program.
  171.     
  172.              The OPTIMIZER (MCO) reads the assembly language output from the
  173.           compiler identifying and replacing "general" code produced by  the
  174.           compiler with more efficent code which is equivalent  in  specific
  175.           cases. This step is  optional,  allowing  you  to  choose  between
  176.           greater compile time and program efficency.
  177.     
  178.              The ASSEMBLER takes  the  assembly  language  produced  by  the
  179.           COMPILER or OPTIMIZER, and produces an OBJECT FILE which  contains
  180.           the executable code and external reference map for the program.
  181.     
  182.              The LINKER combines the executable code from  the  OBJECT  FILE
  183.           with code from  other  programs  which  it  calls  (including  any
  184.           LIBRARY functions), to produce a complete  stand-alone  executable
  185.           program.
  186.     
  187.              The ASSEMBLER and LINKER  are  NOT  included  as  part  of  the
  188.           MICRO-C package. These programs are  specific  to  the  particular
  189.           system, and must be obtained from the system vendor.
  190.     
  191.              Some cross ASSEMBLER's do  not  produce  an  object  file,  but
  192.           generate the executable program directly  instead.  These  systems
  193.           assume that the ENTIRE program is completely contained in a SINGLE
  194.           assembly language file. This type  of  system  prevents  you  from
  195.           using a object LIBRARY which is  an  integral  feature  of  any  C
  196.           programming system.
  197.     
  198.              To  accomodate  this  type  of  development   system,   without
  199.           sacrificing the ability to use a LIBRARY,  a  program  called  the
  200.           SOURCE LINKER (SLINK)  is  included  with  MICRO-C.  This  program
  201.           combines your program  with  library  functions  at  the  ASSEMBLY
  202.           LANGUAGE level, allowing the entire program code to  be  presented
  203.           to the assembler in a single file. See the section  entitled  "THE
  204.           SOURCE LINKER" for additional information.
  205.     MICRO-C                                                          Page: 4
  206.  
  207.  
  208.     2. THE COMMAND CO-ORDINATOR
  209.     
  210.           'CC' is a utility which co-ordinates  the  execution  of  programs
  211.        required for each step of the compilation process to provide a simple
  212.        "one step" compilation  command.  This  MICRO-C  package  includes  a
  213.        version of  the  command  co-ordinator  which  handles  the  commands
  214.        necessary to compile for the 8086 processor  (MCP,  MCC,  MCO,  MASM,
  215.        LINK and EXE2BIN). This program  can  be  modified  as  necessary  to
  216.        handle other processors.
  217.     
  218.        2.1 The CC command
  219.     
  220.              The format of the 'CC' command is:
  221.     
  222.                               CC <name> [options]
  223.     
  224.           2.1.1 Command line options
  225.     
  226.                 -a      - produce ASSEMBLER (.ASM) output file
  227.                 -c      - Include 'C' source as comments in ASM files
  228.                 -f      - Fold identical string constants.
  229.                 -k      - KEEP all temporary files (do not delete)
  230.                 -l      - produce LINKABLE  (.OBJ) output file
  231.                 -o      - OPTIMIZE the output code (using MCO)
  232.                 -p      - use the extended PRE-PROCESSOR (MCP)
  233.                 -q      - QUIET mode (suppress informational messages)
  234.                 -s      - produce SMALL-MODEL (.EXE) output file
  235.                 h=mcdir - specify MICRO-C home directory
  236.                 t=mctmp - specify prefix for TEMPORARY files
  237.     
  238.                 When executing the sub-commands, CC will search the  MICRO-C
  239.              home directory, as well as any  directories  specified  in  the
  240.              'PATH' environment variable. Libraries are  accessed  from  the
  241.              MICRO-C home directory only.
  242.     
  243.                 The environment variable 'MCDIR' is  examined  to  determine
  244.              the path to  the  MICRO-C  home  directory.  If  MCDIR  is  not
  245.              defined, CC will assume the string '\MC'. You may override this
  246.              directory by using the 'h=' option on the command line.
  247.     
  248.                 Intermediate  results  from  each  command  are  stored   in
  249.              "temporary" files, which are fed as input to the next  command.
  250.              Temporary files will be deleted once they are no longer needed,
  251.              except in the case where a command fails.  When  this  happens,
  252.              any temporary file which  was  being  used  as  input  to  that
  253.              command will not be deleted, allowing you to examine it for the
  254.              cause of the error.
  255.     MICRO-C                                                          Page: 5
  256.  
  257.  
  258.                 The environment variable 'MCTMP' is examined to determine  a
  259.              prefix to prepend to temporary file  names.  If  MCTMP  is  not
  260.              defined, CC assumes the default prefix of '$'. You may override
  261.              this prefix by using the 't=' option on the command line.
  262.     
  263.                 Here are example 'SET' commands suitable  for  inclusion  in
  264.              the AUTOEXEC.BAT file, of an IBM/PC based MICRO-C system  which
  265.              has the home directory in 'C:\MC', and a TEMP  directory  on  a
  266.              RAMDISK as drive 'D':
  267.     
  268.                     SET MCDIR=C:\MC
  269.                     SET MCTMP=D:\TEMP\      (Note trailing '\')
  270.     
  271.                 The '-a' option  causes  CC  to  bypass  the  assembler  and
  272.              linker, and produce an assembly source file (<name>.ASM) as the
  273.              output file. If the '-c' option is also used,  this  file  will
  274.              contain the 'C' source code in the form of comments. NOTE:  The
  275.              source code inserted by '-c' will  restrict  the  optimizer  to
  276.              operate only on sections of code produced by a single 'C' line.
  277.     
  278.                 The '-f' option causes the compiler to  "fold"  its  literal
  279.              pool (the area of memory where string  constants  are  stored).
  280.              This means that identical strings  not  contained  in  explicit
  281.              variables, will occur only once in memory. Since most  programs
  282.              never modify such strings, it is usually safe to do this.  Note
  283.              however that this is a violation of the 'C' standard ("The  'C'
  284.              Programming Language"  page  181  -  "All  strings,  even  when
  285.              written identically, are distinct"),  and  it  is  possible  to
  286.              write programs which will not work properly when this option is
  287.              used.
  288.     
  289.                 The '-l' option causes CC to  bypass  the  link  stage,  and
  290.              produce a linkable object module  (<name>.OBJ)  as  the  output
  291.              file.
  292.     
  293.                 The '-s' option causes CC to  link  the  program  using  the
  294.              SMALL  memory  model,   and   produce   an   executable   image
  295.              (<name>.EXE) as the output file. This option  applies  only  to
  296.              those  processors  which  have  a  segmented  architecture  and
  297.              multiple memory models such as the 8086.
  298.     
  299.                 If none of '-a', '-l' or '-s' is specified, CC will link the
  300.              program using the TINY memory  model,  and  produce  a  command
  301.              image (<name>.COM) as the output file.
  302.     MICRO-C                                                          Page: 6
  303.  
  304.  
  305.        2.2 Using multiple object modules
  306.     
  307.              The 'LC' command takes one or more object modules  produced  by
  308.           'CC' with the '-l' option, and links them with  the  libraries  to
  309.           produce an executable module. This module will be given  the  name
  310.           of the first file specified in the argument list.
  311.     
  312.              When compiling large programs which have more than  one  source
  313.           file, you must first compile all modules using 'CC' with the  '-l'
  314.           option, and the use 'LC' to link the resultant object  files  into
  315.           the final executable program.
  316.     
  317.              The '-s' option may be used as the FIRST argument, to cause  LC
  318.           to link in the SMALL model.
  319.                 eg: CC FIRST -l
  320.                     CC SECOND -l
  321.                     LC FIRST SECOND         <-- TINY  Model
  322.                     LC -s FIRST SECOND      <-- SMALL Model
  323.     
  324.              The exact syntax  and  options  available  for  'CC'  and  'LC'
  325.           commands may differ in specific implementations of  the  compiler.
  326.           See the 'READ.ME' file and any additional technical  documentation
  327.           on your distribution disk(s) for details.
  328.     MICRO-C                                                          Page: 7
  329.  
  330.  
  331.     3. THE MICRO-C PROGRAMMING LANGUAGE
  332.     
  333.           The following pages contain a brief summary of  the  features  and
  334.        constructs implemented in MICRO-C.
  335.     
  336.           This document does not  attempt  to  teach  'C'  programming,  and
  337.        assumes that the reader is familiar with the language.
  338.     
  339.        3.1 Constants
  340.     
  341.              The following forms of constants are supported by the compiler:
  342.     
  343.                 <num>       - Decimal number        (0 - 65535)
  344.                 0<num>      - Octal number          (0 - 0177777)
  345.                 0x<num>     - Hexidecimal number    (0x0 - 0xffff)
  346.                 '<char>'    - Character             (1 or 2 chars)
  347.                 "<string>"  - Address of literal string.
  348.     
  349.              The following "special" characters may be used within character
  350.           constants or strings:
  351.     
  352.                 \n          - Newline (line-feed)   (0x0a)
  353.                 \r          - Carriage Return       (0x0d)
  354.                 \t          - Tab                   (0x09)
  355.                 \f          - Formfeed              (0x0c)
  356.                 \b          - Backspace             (0x08)
  357.                 \<num>      - Octal value <num>     (Max. three digits)
  358.                 \x<num>     - Hex value <num>       (Max. two digits)
  359.                 \<char>     - Protect character <char> from input scanner.
  360.     
  361.        3.2 Symbols
  362.     
  363.              Symbol names  may  include  the  characters  'a'-'z',  'A'-'Z',
  364.           '0'-'9', and '_'. The characters '0'-'9' may not be  used  as  the
  365.           first character in the  symbol  name.  Symbol  names  may  be  any
  366.           length, however, only the first 15 characters are significant.
  367.     
  368.              The "char" modifier may be used to declare a symbol as an 8 bit
  369.           wide value, otherwise it is assumed to be 16 bits.
  370.     
  371.                               eg: char input_char;
  372.     
  373.              The "int" modifier may be used to declare a symbol as a 16  bit
  374.           wide value. This is assumed if neither "int" or "char" is given.
  375.     
  376.                                   eg: int abc;
  377.     
  378.              The "unsigned" modifier may be used to declare a symbol  as  an
  379.           unsigned positive only value. Note that unlike some 'C' compilers,
  380.           this modifier may be applied to a character (8 bit) variable.
  381.     
  382.                             eg: unsigned char count;
  383.     MICRO-C                                                          Page: 8
  384.  
  385.  
  386.              The "extern" modifier causes the compiler to be  aware  of  the
  387.           existance and  type  of  a  global  symbol,  but  not  generate  a
  388.           definition for that symbol. This allows the module being  compiled
  389.           to reference a symbol which is defined  in  another  module.  This
  390.           modifier may not be used with local symbols.
  391.     
  392.                             eg: extern char getc();
  393.     
  394.              A  symbol  declared  as  external  may  be  re-declared  as   a
  395.           non-external at a later  point  in  the  code,  in  which  case  a
  396.           definition for it will be generated. This allows  "extern"  to  be
  397.           used to inform the compiler of a function or variable type so that
  398.           it can be referenced  properly  before  that  symbol  is  actually
  399.           defined.
  400.     
  401.              The "static" modifier causes global  symbols  to  be  available
  402.           only in the file where they are defined.  Variables  or  functions
  403.           declared  as  "static"  will  not  be   accessable   as   "extern"
  404.           declarations in other object files, nor will they cause  conflicts
  405.           with duplicate names in those files.
  406.     
  407.                          eg: static int variable_name;
  408.     
  409.              When applied to local symbols,  the  "static"  modifier  causes
  410.           those variables to be allocated in  a  reserved  area  of  memory,
  411.           instead of on the processor stack. This has the  effect  that  the
  412.           contents of the variable will be retained  between  calls  to  the
  413.           function. It also means that the variable  may  be  initialzed  at
  414.           compile time.
  415.     
  416.              The "register" modifier indicates to the  code  generator  that
  417.           this is a high priority variable, and should be kept where  it  is
  418.           easy to get at. Since  its  interpretation  depends  on  the  code
  419.           generator, it is often  ignored  in  simple  implementations.  See
  420.           "Functions" for a  special  use  of  "register"  when  defining  a
  421.           function.
  422.     
  423.                           eg: register unsigned count;
  424.     
  425.              Symbols declared with a preceeding '*' are assumed to be 16 bit
  426.           pointers to the declared type.
  427.     
  428.                              eg: int *pointer_name;
  429.     
  430.              Symbol names declared followed by square brackets  are  assumed
  431.           to be arrays with a number of dimensions equal to  the  number  of
  432.           '[]' pairs that follow. The size of each dimension  is  identified
  433.           by a constant value  contained  within  the  corresponding  square
  434.           brackets.
  435.     
  436.                           eg: char array_name[5][10];
  437.     MICRO-C                                                          Page: 9
  438.  
  439.  
  440.           3.2.1 Global Symbols
  441.     
  442.                 Symbols  declared  outside  of  a  function  definition  are
  443.              considered to  be  global  and  will  have  memory  permanently
  444.              reserved for them. Global symbols are defined by  name  in  the
  445.              output file, allowing other modules to access them.
  446.     
  447.                 Note that the compiler IS case  sensitive,  however  if  the
  448.              assembler you are using is NOT, you  must  be  careful  not  to
  449.              declare any global symbols with names that differ only in case.
  450.     
  451.                 All non-initialized global variables are  generated  at  the
  452.              very end of the output file, after the literal pool is  dumped.
  453.              Since non-initialized globals do not generate object code, this
  454.              allows them to be excluded from the image file when it is saved
  455.              to disk.
  456.     
  457.                 Global variables may be initialized with one or more values,
  458.              which are expressed as a single array of  integers  REGUARDLESS
  459.              of the size and shape of the variable. If more than  one  value
  460.              is expressed, '{' and '}' must be used.
  461.     
  462.                    eg: int i = 10, j[2][2] = { 1, 2, 3, 4 };
  463.     
  464.                 When arrays are declared, a null dimension may  be  used  as
  465.              the dimension size, in which case the size of  the  array  will
  466.              default to the number of initialized values.
  467.     
  468.                          eg: int array[] = { 1, 2, 3 };
  469.     
  470.                 Initialized global variables are automatically saved  within
  471.              the code image,  insuring  that  the  initial  values  will  be
  472.              available at run time. Any non-initialized elements of an array
  473.              which has been partly initialized will be set to zero.
  474.     
  475.                 Non-initialized global variables are not preset in any  way,
  476.              and will be undefined at the beginning of program execution.
  477.     
  478.           3.2.2 Local Symbols
  479.     
  480.                 Symbols declared within a function definition are  allocated
  481.              on the stack, and  exist  only  during  the  execution  of  the
  482.              function.
  483.     
  484.                 To simplify the allocation and de-allocation of stack space,
  485.              all local symbols must be declared  at  the  beginning  of  the
  486.              function before any code producing statements are encountered.
  487.     
  488.                 MICRO-C does not support initialization of non-static  local
  489.              variables in the declaration statement. Since  local  variables
  490.              have to be initialized every time the function is entered,  you
  491.              can get the same effect  using  assignment  statements  at  the
  492.              beginning of the function.
  493.     
  494.                 No type is assumed for  arguments  to  functions.  Arguments
  495.              must be explicitly declared, otherwise they will  be  undefined
  496.              within the scope of the function definition.
  497.     MICRO-C                                                          Page: 10
  498.  
  499.  
  500.           3.2.3 More Symbol Examples
  501.     
  502.             /* Global variables are defined outside of any function */
  503.             char a;                     /* 8 bit signed */
  504.             unsigned char b;            /* 8 bit unsigned */
  505.             int c;                      /* 16 bit signed */
  506.             unsigned int d;             /* 16 bit unsigned */
  507.             unsigned e;                 /* also 16 bit unsigned */
  508.             extern char f();            /* external function returning char */
  509.             static int g;               /* 16 bit signed, local to file */
  510.             int h[2] = { 1, 2 };        /* initialized array (2 ints) */
  511.     
  512.             main(a, b)                  /* "int" function containing code */
  513.             /* Function arguments are defined between function name and body */
  514.                 int a;                  /* 16 bit signed */
  515.                 unsigned char *b;       /* pointer to 8 bit unsigned */
  516.             {
  517.             /* Local variables are defined inside the function body */
  518.             /* Note that in MICRO-C, only "static" locals can be initialized */
  519.                 unsigned c;             /* 16 bit unsigned */
  520.                 static char d[5];       /* 8 bit signed, reserved in memory */
  521.                 static int e = 1;       /* 16 bit signed, initial value is 1 */
  522.             /* Function code goes here ... */
  523.                 c = 0;                  /* Initialize 'c' to zero */
  524.                 strcpy(d, "Name");      /* Initialize 'd' to "name" */
  525.             }
  526.     MICRO-C                                                          Page: 11
  527.  
  528.  
  529.        3.3 Arrays & Pointers
  530.     
  531.              When MICRO-C passes an array to a function, it actually  passes
  532.           a POINTER to the array. References to arrays which  are  arguments
  533.           are automatically performed through the pointer.
  534.     
  535.              This allows the use of pointers and arrays to be interchangable
  536.           through the context of a function call. Ie: An array passed  to  a
  537.           function may be declared and used as  a  pointer,  and  a  pointer
  538.           passed to a function may be declared and used as an array.
  539.     
  540.        3.4 Functions
  541.     
  542.              Functions are  essentially  initialized  global  symbols  which
  543.           contain executable code.
  544.     
  545.              MICRO-C accepts  any  valid  value  as  a  function  reference,
  546.           allowing  some  rather  unique  (although  non-standard)  function
  547.           calls.
  548.     
  549.           For example:
  550.     
  551.                 function();     /* call function */
  552.                 variable();     /* call contents of a variable */
  553.                 (*var)();       /* call indirect through variable */
  554.                 (*var[x])();    /* call indirect through indexed array */
  555.                 0x5000();       /* call address 0x5000 */
  556.     
  557.              Since this is a single pass compiler, operands to functions are
  558.           evaluated and pushed on the stack in the order in which  they  are
  559.           encountered, leaving the last operand closest to the  top  of  the
  560.           stack. This is the opposite order from which  many  'C'  compilers
  561.           push operands.
  562.     
  563.              For functions with a fixed number of arguments,  the  order  of
  564.           which operands  are  passed  is  of  no  importance,  because  the
  565.           compiler looks after generating  the  proper  stack  addresses  to
  566.           reference variables.  HOWEVER,  functions  which  use  a  variable
  567.           number of arguments are affected for two reasons:
  568.     
  569.           1) The location of the LAST arguments are known (as fixed  offsets
  570.              from the stack pointer) instead of the FIRST.
  571.     
  572.           2) The symbols defined as arguments  in  the  function  definition
  573.              represent the LAST arguments instead of the FIRST.
  574.     
  575.              If a function is declared as "register", it  serves  a  special
  576.           purpose and causes the accumulator to be loaded with the number of
  577.           arguments passed whenever the function is called. This allows  the
  578.           function to know how many  arguments  were  passed  and  therefore
  579.           determine the location of the first argument.
  580.     MICRO-C                                                          Page: 12
  581.  
  582.  
  583.        3.5 Structures & Unions
  584.     
  585.              Combinations of other variable  types  can  be  organized  into
  586.           STRUCTURES or UNIONS, which allow them  to  be  manipulated  as  a
  587.           single entity.
  588.     
  589.              In a structure, the  individual  items  occur  sequentially  in
  590.           memory, and the total size of the structure  is  the  sum  of  its
  591.           elements. Structures are usually  used  to  create  "records",  in
  592.           which related items are grouped together. An array  of  structures
  593.           is the common method of implementing an "in-memory" database.
  594.     
  595.              A union is similar to a structure, except that  the  individual
  596.           items are overlaid in memory, and the total size of the  union  is
  597.           the size of its largest element. Unions are usually used to  allow
  598.           a single block of memory to be accessed as different 'C'  variable
  599.           types. An example of this would be in handling a message  received
  600.           in memory, in which a "type" byte indicates how the  remainder  of
  601.           the message data should be interpreted.
  602.     
  603.              Here are some example of how structures are  defined  and  used
  604.           (unions are defined and used in an identical manner,  except  that
  605.           the word 'union' is substituted for 'struct'):
  606.     
  607.             /* Create structure named 'data' with 'a,b,c & d' as members */
  608.             struct {
  609.                 int a;
  610.                 int b;
  611.                 char c;
  612.                 char d; } data;
  613.     
  614.             /* Create structure template named 'mystruc'... */
  615.             /* No actual structure variable is defined */
  616.             struct mystruc {
  617.                 int a;
  618.                 int b;
  619.                 char c;
  620.                 char d; };
  621.     
  622.             /* Create structure named 'data' using above template */
  623.             struct mystruc data;
  624.     
  625.             /* Create structure template 'mystruc', AND define a */
  626.             /* structure variable named 'data' */
  627.             struct mystruc {
  628.                 int a;
  629.                 int b;
  630.                 char c;
  631.                 char d; } data;
  632.     MICRO-C                                                          Page: 13
  633.  
  634.  
  635.             /* Create an array of structures, a pointer to a structure */
  636.             /* and an array of pointers to a structure *
  637.             struct mystruct array[10], *pointer, *parray[10];
  638.     
  639.             /* To set value in structure variable/members */
  640.             data.a = 10;            /* Direct access */
  641.             array[1].b = 10;        /* Direct array access */
  642.             pointer->c = 'a';       /* Pointer access */
  643.             parray[2]->d = 'b';     /* Pointer array access */
  644.     
  645.             /* To read value in structure variable/members */
  646.             value = data.a;         /* Direct access */
  647.             value = data[1].b;      /* Direct array access */
  648.             value = pointer->c;     /* Pointer access */
  649.             value = parray[2]->d;   /* Pointer array access */
  650.     
  651.           3.5.1 Notes on MICRO-C structure implementation:
  652.     
  653.                 Structures and Unions as implemented in MICRO-C are  similar
  654.              to the implementation of the original UNIX  'C'  compiler,  and
  655.              are bound by similar limitations, as  well  as  a  few  MICRO-C
  656.              specific ones.  Here  is  a  list  of  major  differences  when
  657.              compared to a modern ANSI compiler:
  658.     
  659.                 All structure and member names MUST  be  unique  within  the
  660.              scope of the definition. A special case  exists,  where  common
  661.              member names may be used in  multiple  structure  templates  if
  662.              they have EXACTLY the same type and offset into the  structure.
  663.              This also saves symbol table memory, since only one copy of the
  664.              member definition is actually kept.
  665.     
  666.                 MICRO-C does NOT pass entire structures to functions on  the
  667.              stack. Like  arrays,  MICRO-C  passes  structures  by  ADDRESS.
  668.              Structure variables which are function arguments  are  accessed
  669.              through pointers. For source code compatibility with  compilers
  670.              which do pass the entire structure, if you declare the argument
  671.              as a direct (non-pointer) structure, the direct ('.')  operator
  672.              is used to dereference it, even though it is actually a pointer
  673.              reference.
  674.     
  675.                 If you  MUST  have  a  local  copy  of  the  structure,  use
  676.              something like:
  677.     
  678.                 func(sptr)
  679.                     struct mystruc *sptr;
  680.                 {
  681.                     struct mystruc data;
  682.                     memcpy(data, sptr, sizeof(data));
  683.                     ...
  684.                 }
  685.     MICRO-C                                                          Page: 14
  686.  
  687.  
  688.                 To obtain the size of a structure from  its  template  name,
  689.              use the 'struct'  keyword  in  conjunction  with  the  'sizeof'
  690.              operator.   In   the   above   example,   you   could   replace
  691.              'sizeof(data)' with 'sizeof(struct mystruc)'.
  692.     
  693.                 To obtain the size of a structure member, you  must  specify
  694.              it in the context of a structure reference with another symbol:
  695.     
  696.               sizeof(variable.member) or sizeof(variable->member)
  697.     
  698.                 NOTE: The current compiler allows almost any symbol  to  the
  699.              left of the '.' or '->' operator in a 'sizeof', however  future
  700.              versions of the compiler may insist on a structure variable  or
  701.              a pointer to structure variable.
  702.     
  703.                 Pointers to structures are internally stored as pointers  to
  704.              'char', and therefore will only increment/decrement by  1  when
  705.              ++/-- is used. To advance a pointer by the size of a structure,
  706.              use:
  707.     
  708.                          ptr += sizeof(struct mystruc)
  709.     
  710.                 The 'struct' and 'union' keywords  are  not  accepted  in  a
  711.              TYPECAST. This is most commonly used to setup a  pointer  to  a
  712.              structure. Since MICRO-C stores its pointers to  structures  as
  713.              pointers to char, you can use (char*) as the typecast, and  get
  714.              the same functionality.
  715.     
  716.                 A structure name by itself (without  '.member')  acts  in  a
  717.              manner similar to a character array name.  With  no  operation,
  718.              the address of the structure is returned. You can also use '[]'
  719.              to access  individual  bytes  in  the  structure  by  indexing,
  720.              although doing so is highly non-portable.
  721.     
  722.                 MICRO-C allows static or global structures to be initialized
  723.              in the declaration, however the initial values are read  as  an
  724.              array of bytes, and are assigned directly to  structure  memory
  725.              without regard for the type or size of its members:
  726.     
  727.                 struct mystruc data = { 0, 1, 0, 2, 3, 4 };
  728.                 /* A=0:1, B=0:2, C=3, D=4 */
  729.     
  730.                 You can use INT and CHAR to switch back  and  forth  between
  731.              word/byte initialization within the value list:
  732.     
  733.                 struct mystruct data = { int 0, 1, char 2, 3 };
  734.                 /* A=0, B=1, C=2, D=3 */
  735.     
  736.                 MICRO-C does not WORD ALIGN structure elements. When using a
  737.              processor which requires word alignment, it is the  programmers
  738.              responsibility to maintain alignment, using filler  bytes  etc.
  739.              when necessary.
  740.     MICRO-C                                                          Page: 15
  741.  
  742.  
  743.        3.6 Control Statements
  744.     
  745.              The following control statements are implemented in MICRO-C:
  746.     
  747.                 if(expression)
  748.                     statement;
  749.     
  750.                 if(expression)
  751.                     statement;
  752.                 else
  753.                     statement;
  754.     
  755.                 while(expression)
  756.                     statement;
  757.     
  758.                 do
  759.                     statement;
  760.                 while expression;
  761.     
  762.                 for(expression; expression; expression)
  763.                     statement;
  764.     
  765.                 return;
  766.     
  767.                 return expression;
  768.     
  769.                 break;
  770.     
  771.                 continue;
  772.     
  773.                 switch(expression) {
  774.                     case constant_expression :
  775.                         statement;
  776.                         ...
  777.                         break;
  778.                     case constant_expression :
  779.                         statement;
  780.                         ...
  781.                         break;
  782.                         .
  783.                         .
  784.                         .
  785.                     default:
  786.                         statement; }
  787.     
  788.                 label: statement;
  789.     
  790.                 goto label;
  791.     
  792.                 asm "...";
  793.     
  794.                 asm {
  795.                     ...
  796.                     }
  797.     MICRO-C                                                          Page: 16
  798.  
  799.  
  800.     3.6.1 Notes on Control Structures
  801.     
  802.         1)  Any "statement" may be a single statement or a compound
  803.             statement enclosed within '{' and '}'.
  804.     
  805.         2)  All three "expression"s in the "for" command are optional.
  806.     
  807.         3)  If a "case" selection does not end with "break;", it will
  808.             "fall through" and execute the following case as well.
  809.     
  810.         4)  Expressions following 'return' and 'do/while' do not have
  811.             to be contained in brackets (although this is permitted).
  812.     
  813.         5)  Label names may preceed any statement, and must be any
  814.             valid symbol name, followed IMMEDIATELY by ':' (No spaces
  815.             are allowed). Labels are considered LOCAL to a function
  816.             definition and will only be accessable within the scope
  817.             of that function.
  818.     
  819.         6)  The 'asm' statement used to implement the inline assembly
  820.             language capability of MICRO-C accepts two forms:
  821.                 asm "...";      <- Assemble single line.
  822.                 asm {           <- Assemble multiple lines.
  823.                     ...
  824.                     }
  825.     MICRO-C                                                          Page: 17
  826.  
  827.  
  828.        3.7 Expression Operators
  829.     
  830.              The following expression operators are implemented in MICRO-C:
  831.     
  832.     3.7.1 Unary Operators
  833.     
  834.         -           - Negate
  835.         ~           - Bitwise Complement
  836.         !           - Logical complement
  837.         ++          - Pre or Post increment
  838.         --          - Pre or post decrement
  839.         *           - Indirection
  840.         &           - Address of
  841.         sizeof      - Size of a object or type
  842.         (type)      - Typecast
  843.     
  844.     3.7.2 Binary Operators
  845.     
  846.         +           - Addition
  847.         -           - Subtraction
  848.         *           - Multiplication
  849.         /           - Division
  850.         %           - Modulus
  851.         &           - Bitwise AND
  852.         |           - Bitwise OR
  853.         ^           - Bitwise EXCLUSIVE OR
  854.         <<          - Shift left
  855.         >>          - Shift right
  856.         ==          - Test for equality
  857.         !=          - Test for inequality
  858.         >           - Test for greater than
  859.         <           - Test for less than
  860.         >=          - Test for greater than or equal to
  861.         <=          - Test for less than or equal to
  862.         &&          - Logical AND
  863.         ||          - Logical OR
  864.         =           - Assignment
  865.         +=          - Add to self assignment
  866.         -=          - Subtract from self assignment
  867.         *=          - Multiply by self assignment
  868.         /=          - Divide by and reassign assignment
  869.         %=          - Modular self assignment
  870.         &=          - AND with self assignment
  871.         |=          - OR with self assignment
  872.         ^=          - EXCLUSIVE OR with self assignment
  873.         <<=         - Shift left self assignment
  874.         >>=         - Shift right self assignment
  875.     MICRO-C                                                          Page: 18
  876.  
  877.  
  878.     NOTES:
  879.     
  880.         1)  The expression "a && b" returns 0 if "a" is zero, otherwise the
  881.             value of "b" is returned. The "b" operand is NOT evaluated if
  882.             "a" is zero.
  883.     
  884.         2)  The expression "a || b" returns the value of "a" if it is not 0,
  885.             otherwise the value of "b" is returned. The "b" operand is NOT
  886.             evaluated if "a" is non-zero.
  887.     
  888.     3.7.3 Other Operators
  889.     
  890.         ;           - Ends a statement.
  891.         ,           - Allows several expressions in one statement.
  892.                     + Separates symbol names in multiple declarations.
  893.                     + Separates constants in multi-value initialization.
  894.                     + Separates operands in function calls.
  895.         ?           - Conditional expression (ternary operator).
  896.         :           - Delimits labels, ends CASE and separates conditionals.
  897.         .           - Access a structure member directly.
  898.         ->          - Access a structure member through a pointer.
  899.         { }         - Defines a BLOCK of statements.
  900.         ( )         - Forces priority in expression, indicates function calls.
  901.         [ ]         - Indexes arrays. If fewer index values are given than the
  902.                       number of dimensions which are defined for the array,
  903.                       the value returned will be a pointer to the appropriate
  904.                       address.
  905.     
  906.                     Eg:
  907.                         char a[5][2];
  908.     
  909.                         a[3] returns address of forth row of two characters.
  910.                         (remember index's start from zero)
  911.     
  912.                         a[3][0] returns the character at index [3][0];
  913.     MICRO-C                                                          Page: 19
  914.  
  915.  
  916.        3.8 Inline Assembly Language
  917.     
  918.              Although 'C' is a powerful and  flexible  language,  there  are
  919.           sometimes instances where a particular operation must be  peformed
  920.           at the assembly language level. This most  often  involves  either
  921.           some processor feature for which there  is  no  corresponding  'C'
  922.           operation, or a section of very time critical code.
  923.     
  924.              MICRO-C provides access to assembly  language  with  the  'asm'
  925.           statement, which has two basic forms. The first is:
  926.     
  927.                                   asm "..." ;
  928.     
  929.              In this form, the entire  text  contained  between  the  double
  930.           quote characters (") is output as a single line to the  assembler.
  931.           Note that a  semicolon  is  required,  just  like  any  other  'C'
  932.           statement.
  933.     
  934.              Since this is a standard 'C' string, you can  use  any  of  the
  935.           "special" characters, and thus you could output multiple lines  by
  936.           using '\n' within the string. Another important characteristic  of
  937.           it being a string is that it will be protected from  pre-processor
  938.           substitution.
  939.     
  940.              The second form of the 'asm' statement is:
  941.     
  942.                                      asm {
  943.                                       ...
  944.                                        }
  945.     
  946.              In this form, all lines between '{' and '}' are output  to  the
  947.           assembler. Any text following the opening '{' (on the  same  line)
  948.           is ignored. Due to  the  unknown  characteristics  of  the  inline
  949.           assembly code, the closing '}' will only be recognized when it  is
  950.           the first non-whitespace character on a line.
  951.     
  952.              The integral pre-processor will not perform substitution on the
  953.           inline assembly code, however  the  external  pre-processor  (MCP)
  954.           will substitute in this form. This allows you to  create  assembly
  955.           language "macros" using MCP, and have parameters substituted  into
  956.           them when they are expanded:
  957.     
  958.             /*
  959.              * This macro issues a 'SETB' instruction for its parameter
  960.              */
  961.             #define setbit(bit) asm {\
  962.                 SETB bit\
  963.             }
  964.     
  965.             /*
  966.              * This macro WILL NOT WORK, since the 'bit' operand to the SETB
  967.              * instruction is contained within a string and is therefore
  968.              * protected from substitution by the pre-processor
  969.              */
  970.             #define setbit(bit) asm " SETB bit";
  971.     MICRO-C                                                          Page: 20
  972.  
  973.  
  974.        3.9 Preprocessor Commands
  975.     
  976.              The  MICRO-C  compiler  supports  the  following  pre-processor
  977.           commands. These commands are recognized only if they occur at  the
  978.           beginning of the input line.
  979.     
  980.              NOTE:  This  describes  the  limited  pre-processor  which   is
  981.           integral to the  compiler,  see  also  the  section  on  the  more
  982.           powerful external processor (MCP).
  983.     
  984.           3.9.1 #define <name> <replacement_text>
  985.     
  986.                 The "#define" command allows a global name  to  be  defined,
  987.              which will be replaced with the indicated text whenever  it  is
  988.              encountered in the input file. This occurs prior to  processing
  989.              by the compiler.
  990.     
  991.           3.9.2 #file <filename>
  992.     
  993.                 Sets the filename of the currently  procssing  file  to  the
  994.              given  string.  This  command   is   used   by   the   external
  995.              pre-processor (MCP) to insure that error messages indicate  the
  996.              original source file.
  997.     
  998.           3.9.3 #include <filename>
  999.     
  1000.                 This command causes the indicated file to be opened and read
  1001.              in as the source  text.  When  the  end  of  the  new  file  is
  1002.              encountered, processing will continue with the  line  following
  1003.              "#include" in the original file.
  1004.     
  1005.           3.9.4 #ifdef <name>
  1006.     
  1007.                 Processes the following lines (up to #else or  #endif)  only
  1008.              if the given name is defined.
  1009.     
  1010.           3.9.5 #ifndef <name>
  1011.     
  1012.                 Processes the following lines (up to #else or  #endif)  only
  1013.              if the given name is NOT defined.
  1014.     
  1015.           3.9.6 #else
  1016.     
  1017.                 Processes the following lines (up to  #endif)  only  if  the
  1018.              preceeding #ifdef or #ifndef was false.
  1019.     
  1020.           3.9.7 #endif
  1021.     
  1022.                 Terminates #ifdef and #ifndef
  1023.     
  1024.                 NOTE: The integral pre-processor does not support nesting of
  1025.              the #ifdef and #idndef constructs. If you wish  to  nest  these
  1026.              conditionals, you must use the external pre-processor (MCP).
  1027.     MICRO-C                                                          Page: 21
  1028.  
  1029.  
  1030.        3.10 Error Messages
  1031.     
  1032.              When MICRO-C detects an  error,  it  outputs  an  informational
  1033.           message indicating the type of problem encountered.
  1034.     
  1035.              The error message is preceeded by the filename and line  number
  1036.           where the error occured:
  1037.     
  1038.                            program.c(5): Syntax error
  1039.     
  1040.              In the above example, the error occured in the file "program.c"
  1041.           at line 5.
  1042.     
  1043.              The following error messages are produced by the compiler:
  1044.     
  1045.           3.10.1 Compilation aborted
  1046.     
  1047.                 The preceeding error was so severe than the compiler  cannot
  1048.              proceed.
  1049.     
  1050.           3.10.2 Constant expression required
  1051.     
  1052.                 The compiler requires a constant  expression  which  can  be
  1053.              evaluated at compile time (ie: no variables).
  1054.     
  1055.           3.10.3 Declaration must preceed code.
  1056.     
  1057.                 All local variables must be defined at the beginning of  the
  1058.              function, before any code producing statements are processed.
  1059.     
  1060.           3.10.4 Dimension table exhausted
  1061.     
  1062.                 The compiler has encountered more  active  array  dimensions
  1063.              than it can handle.
  1064.     
  1065.           3.10.5 Duplicate local: 'name'
  1066.     
  1067.                 You have declared the named  local  symbol  more  than  once
  1068.              within the same function definition.
  1069.     
  1070.           3.10.6 Duplicate global: 'name'
  1071.     
  1072.                 You have declared the named global symbol more than once.
  1073.     
  1074.           3.10.7 Expected '<token>'
  1075.     
  1076.                 The compiler  was  expecting  the  given  token,  but  found
  1077.              something else.
  1078.     
  1079.           3.10.8 Expression stack overflow
  1080.     
  1081.                 The compiler has found a more complicated expression than it
  1082.              can handle. Check that it is of  correct  syntax,  and  if  so,
  1083.              break it up into two simpler expressions.
  1084.     MICRO-C                                                          Page: 22
  1085.  
  1086.  
  1087.           3.10.9 Expression stack underflow
  1088.     
  1089.                 The compiler has made an error in  parsing  the  expression.
  1090.              Check that it is of correct syntax.
  1091.     
  1092.           3.10.10 Illegal indirection
  1093.     
  1094.                 You have attempted to perform an indirect operation ('*'  or
  1095.              '[]') on an entity which is not a pointer or array. This  error
  1096.              will also result if you attempt to index  an  array  with  more
  1097.              indices than it has dimensions.
  1098.     
  1099.           3.10.11 Illegal initialization
  1100.     
  1101.                 Local variables may not be initialized  in  the  declaration
  1102.              statement. Use assignments at the  beginning  of  the  function
  1103.              code to perform the initialization.
  1104.     
  1105.           3.10.12 Illegal nested function
  1106.     
  1107.                 You may not declare a  function  within  the  definition  of
  1108.              another function.
  1109.     
  1110.           3.10.13 Improper type of symbol: 'name'
  1111.     
  1112.                 The named  symbol  is  not  of  the  correct  type  for  the
  1113.              operation that you are attempting. Eg: 'goto' where the  symbol
  1114.              is not a label.
  1115.     
  1116.           3.10.14 Improper #else/#endif
  1117.     
  1118.                 A #else or #endif statement is out of place.
  1119.     
  1120.           3.10.15 Inconsistant member offset: 'name'
  1121.     
  1122.                 The named structure member is multiply defined,  and  has  a
  1123.              different offset from its first definition.
  1124.     
  1125.           3.10.16 Inconsistant member type: 'name'
  1126.     
  1127.                 The named structure member is multiply defined,  and  has  a
  1128.              different type from its first definition.
  1129.     
  1130.           3.10.17 Inconsistant re-declaration: 'name'
  1131.     
  1132.                 You have attempted to redefine  the  named  external  symbol
  1133.              with a type which does not match its previously declared type.
  1134.     
  1135.           3.10.18 Incorrect declaration
  1136.     
  1137.                 A statement occuring outside of a function definition is not
  1138.              a valid declaration for a function or global variable.
  1139.     MICRO-C                                                          Page: 23
  1140.  
  1141.  
  1142.           3.10.19 Invalid '&' operation
  1143.     
  1144.                 You have attempted to reference  the  address  of  something
  1145.              that has no address. This error also occurs when you attempt to
  1146.              take the address of an array without giving it a  full  set  of
  1147.              indicies. Since the address is already returned in  this  case,
  1148.              simply drop the '&'. (The error occurs because you  are  trying
  1149.              to take the address of an address).
  1150.     
  1151.           3.10.20 Macro expansion too deep
  1152.     
  1153.                 The compiler has encountered a nested macro reference  which
  1154.              is too deep to be resolved.
  1155.     
  1156.           3.10.21 Macro space exhausted
  1157.     
  1158.                 The compiler has encountered  more  macro  ("#define")  text
  1159.              than it has room to store.
  1160.     
  1161.           3.10.22 No active loop
  1162.     
  1163.                 A "continue" or "break" statement was  encountered  when  no
  1164.              loop is active.
  1165.     
  1166.           3.10.23 No active switch
  1167.     
  1168.                 A "case" or "default"  statement  was  encountered  when  no
  1169.              "switch" statement is active.
  1170.     
  1171.           3.10.24 Not an argument: 'name'
  1172.     
  1173.                 You have declared the named variable as an argument, but  it
  1174.              does not appear in the argument list.
  1175.     
  1176.           3.10.25 Non-assignable
  1177.     
  1178.                 You have attempted an operation which results in  assignment
  1179.              of a value to an entity which cannot be assigned. (eg: 1 = 2);
  1180.     
  1181.           3.10.26 Numeric constant required
  1182.     
  1183.                 The compiler requires a constant expression which returns  a
  1184.              simple numeric value.
  1185.     
  1186.           3.10.27 String space exhausted
  1187.     
  1188.                 The compiler has encountered more literal  strings  than  it
  1189.              has room store.
  1190.     
  1191.           3.10.28 Symbol table full
  1192.     
  1193.                 The compiler has encountered more symbol definitions than it
  1194.              can handle.
  1195.     MICRO-C                                                          Page: 24
  1196.  
  1197.  
  1198.           3.10.29 Syntax error
  1199.     
  1200.                 The statement shown does not follow syntax rules and  cannot
  1201.              be parsed.
  1202.     
  1203.           3.10.30 Too many active cases
  1204.     
  1205.                 The compiler has run out of space  for  storing  switch/case
  1206.              tables. Reduce the number of active "cases".
  1207.     
  1208.           3.10.31 Too many defines
  1209.     
  1210.                 The compiler has encountered more '#define' statements  than
  1211.              it can handle. Reduce the number of #defines.
  1212.     
  1213.           3.10.32 Too many errors
  1214.     
  1215.                 The compiler is aborting because of excessive errors.
  1216.     
  1217.           3.10.33 Too many includes
  1218.     
  1219.                 The compiler has encountered more  nested  "#include"  files
  1220.              than it can handle.
  1221.     
  1222.           3.10.34 Too many initializers
  1223.     
  1224.                 You have specified more initialization values than there are
  1225.              locations in the global variable.
  1226.     
  1227.           3.10.35 Type clash
  1228.     
  1229.                 You have attempted to use a  value  in  a  manner  which  is
  1230.              inconsistant with its typing information.
  1231.     
  1232.           3.10.36 Unable to open: 'name'
  1233.     
  1234.                 A "#include" command specified the named file,  which  could
  1235.              not be opened.
  1236.     
  1237.           3.10.37 Undefined: 'name'
  1238.     
  1239.                 You have referenced a name which is not defined as  a  local
  1240.              or global symbol.
  1241.     
  1242.           3.10.38 Unknown structure/member: 'name'
  1243.     
  1244.                 You have referenced a  structure  template  or  member  name
  1245.              which is not defined.
  1246.     
  1247.           3.10.39 Unreferenced: 'name'
  1248.     
  1249.                 The named  symbol  was  defined  as  a  local  symbol  in  a
  1250.              function, but was never used in that function. This error  will
  1251.              occur at the end of  the  function  definition  containing  the
  1252.              symbol declaration. It is only a warning, and  will  not  cause
  1253.              the compile to abort.
  1254.     MICRO-C                                                          Page: 25
  1255.  
  1256.  
  1257.           3.10.40 Unresolved: 'name'
  1258.     
  1259.                 The named symbol was forward  referenced  (Such  as  a  GOTO
  1260.              label), and was never defined. This error will occur at the end
  1261.              of the function definition containing the reference.
  1262.     
  1263.           3.10.41 Unterminated conditional
  1264.     
  1265.                 The end of file was encountered  when  a  "#if"  or  "#else"
  1266.              conditional block was being processed.
  1267.     
  1268.           3.10.42 Unterminated function
  1269.     
  1270.                 The  end  of  the  file  was  encountered  when  a  function
  1271.              definition was still open.
  1272.     MICRO-C                                                          Page: 26
  1273.  
  1274.  
  1275.        3.11 Quirks
  1276.     
  1277.              Due  to  its  background  as  a  highly  compact  and  portable
  1278.           compiler, and its target application in embedded systems,  MICRO-C
  1279.           deviates from standard 'C' in some areas. The following is a short
  1280.           summary of the major infractions and quirks:
  1281.     
  1282.              The operands to '#' commands are  parsed  based  on  separating
  1283.           spaces, and any portion of the line not required  is  ignored.  In
  1284.           particular, the '#define' command only accepts a definition up  to
  1285.           the next space or tab character.
  1286.     
  1287.             eg: #define APLUSONE A+1        <-- uses "A+1"
  1288.                 #define APLUSONE A +1       <-- uses "A"
  1289.     
  1290.              Comments are stripped by the token scanner, which occurs  AFTER
  1291.           the '#' commands are processed.
  1292.     
  1293.             eg: #define NULL    /* comment */   <-- uses "/*"
  1294.     
  1295.              Note that since comments can therefore be included in "#define"
  1296.           symbols, you can use "/**/" to simulate spaces between tokens.
  1297.     
  1298.             eg: #define BYTE unsigned/**/char
  1299.     
  1300.              Include filenames are not delimited by '""'  or  '<>'  and  are
  1301.           passed to the operating system exactly as entered.
  1302.     
  1303.             eg: #include \mc\stdio.h
  1304.     
  1305.              NOTE:  The  above  quirks  do  not  apply  when  the   external
  1306.           pre-processor (MCP) is used.
  1307.     
  1308.              The appearance of a variable name in the argument  list  for  a
  1309.           function  declaration  serves  only  to  identify  that  variables
  1310.           location on the stack. MICRO-C will not define the variable unless
  1311.           it is explicitly declared (between the argument list and the  main
  1312.           function body). In other words, all arguments to a  function  must
  1313.           be explicitly declared.
  1314.     
  1315.              MICRO-C is more  strict  about  its  handling  of  the  ADDRESS
  1316.           operator ('&') than most other compilers. It will produce an error
  1317.           message if you attempt to take the address of  a  value  which  is
  1318.           already a fixed address (such as an array name without a full  set
  1319.           of indicies). Since an address is already produced in such  cases,
  1320.           simply drop the '&'.
  1321.     
  1322.              The 'x' in '0x' and '\x' is accepted in lower case only.
  1323.     MICRO-C                                                          Page: 27
  1324.  
  1325.  
  1326.              When operating on pointers, MICRO-C only scales  the  increment
  1327.           (++), decrement (--) and index ([]) operations to account for  the
  1328.           size of the pointer:
  1329.     
  1330.             eg: char *cptr;     /* pointer to character */
  1331.                 int  *iptr;     /* pointer to integer */
  1332.                 ++cptr;         /* Advance one character */
  1333.                 ++iptr;         /* Advance one integer */
  1334.                 cptr[10];       /* Access the tenth character */
  1335.                 iptr[10];       /* Access the tenth integer */
  1336.                 cptr += 10;     /* Advance 10 characters */
  1337.                 iptr += 10;     /* Advance ONLY FIVE integers */
  1338.     
  1339.             NOTE: A portable way to advance "iptr" by integers is:
  1340.     
  1341.                 iptr = &iptr[10];   /* Advance 10 integers */
  1342.     
  1343.              Incrementing a pointer to a structure will advance only one (1)
  1344.           byte  in  memory.  To  advance  to  the  "next"  instance  of  the
  1345.           structure, use:
  1346.     
  1347.                         ptr += sizeof(struct template);
  1348.     
  1349.              The INDEXING operator '[]' is not commutative  in  MICRO-C.  In
  1350.           other words 'array[index]' cannot be expressed as 'index[array]'.
  1351.     
  1352.              MICRO-C does  not  support  "complex"  declarations  which  use
  1353.           brackets '()' for other than function parameters. These  are  most
  1354.           often used in establishing pointers to functions:
  1355.                     int (*a)();     /* Pointer to function returning INT */
  1356.                     (*a)();         /* Call address in 'a' */
  1357.     
  1358.              Since MICRO-C allows you to call any value by following it with
  1359.           '()', you can get  the  desired  effect  in  the  above  case,  by
  1360.           declaring 'a' as a simple pointer to int, and calling it with  the
  1361.           same syntax:
  1362.                     int *a;         /* Pointer to INT */
  1363.                     (*a)();         /* Call address in 'a' */
  1364.     
  1365.              MICRO-C will not output external  declarations  to  the  output
  1366.           file  for  any  variables  or  functions  which  are  declared  as
  1367.           "extern", unless that symbol is actually  referenced  in  the  'C'
  1368.           source code. This prevents "extern" declarations in system  header
  1369.           files (such as "stdio.h") which are used as  prototypes  for  some
  1370.           library functions from causing those functions to be  loaded  into
  1371.           the  object  file.  Therefore,  any  "extern"  symbols  which  are
  1372.           referenced only by inline assembly code must be  declared  in  the
  1373.           assembly code, not by the MICRO-C "extern" statement.
  1374.     MICRO-C                                                          Page: 28
  1375.  
  1376.  
  1377.              Unlike some  'C'  compilers,  MICRO-C  will  process  character
  1378.           expressions using only  BYTE  values.  Character  values  are  not
  1379.           promoted to INT unless there is  an  INT  value  involved  in  the
  1380.           expression. This results in much more efficent code  when  dealing
  1381.           with characters, particularily  on  small  processors  which  have
  1382.           limited 16 bit instructions. Consider the statement:
  1383.     
  1384.                                  return c + 1;
  1385.     
  1386.              On some compilers, this will sign extend the character variable
  1387.           'c' into an integer value, and then ADD an integer  1  and  return
  1388.           the  result.  MICRO-C  will  ADD  the  character  variable  and  a
  1389.           character 1, and then promote the result to INT  before  returning
  1390.           it (results of expressions as  operands  to  'return'  are  always
  1391.           promoted to int).
  1392.     
  1393.              Unfortunately, programs have been written  which  rely  on  the
  1394.           automatic promotion of characters to INTs to  work  properly.  The
  1395.           most common source of problems is code  which  attempts  to  treat
  1396.           CHAR variables as UNSIGNED values (many older  compilers  did  not
  1397.           support UNSIGNED CHAR). For example:
  1398.     
  1399.                                 return c & 255;
  1400.     
  1401.              In a compiler which always evaluates character  expressions  as
  1402.           INT, the above statement will extract the value of 'c' as positive
  1403.           integer ranging from 0 to 255.
  1404.     
  1405.              In MICRO-C, ANDing a character with 255  results  in  the  same
  1406.           character, which gets promoted to an integer  value  ranging  from
  1407.           -128 to 127. To force the promotion  within  the  expression,  you
  1408.           could CAST the variable to an INT:
  1409.     
  1410.                               return (int)c & 255;
  1411.     
  1412.              The same objective can be achieved  in  a  more  efficent  (and
  1413.           correct) manner by declaring the variable 'c' as UNSIGNED CHAR, or
  1414.           by CASTing the variable to an UNSIGNED value:
  1415.     
  1416.                               return (unsigned)c;
  1417.     
  1418.              Note that this is not only more clearly shows the intent of the
  1419.           programmer, but also results is more efficent code generated.
  1420.     MICRO-C                                                          Page: 29
  1421.  
  1422.  
  1423.              A related quirk arises because most processors do not support a
  1424.           simple efficent method for adding or subtracting a  SIGNED  8  bit
  1425.           quantity and a 16 bit quantity. The code generators supplied  with
  1426.           MICRO-C make the assumption that character values being  added  or
  1427.           subtracted to/from integers will contain only POSITIVE values, and
  1428.           thus use UNSIGNED  addition/subtraction.  This  allows  much  more
  1429.           efficent code to be generated, as the carry/borrow  from  the  low
  1430.           order byte of the operation is simply propagated to the high order
  1431.           byte of the result (an operation  supported  in  hardware  by  the
  1432.           CPU).
  1433.     
  1434.              For those rare instances where you do wish  to  add/subtract  a
  1435.           potentially negative character value to/from an int, you can force
  1436.           the expression to be performed  in  less  efficent  fully  16  bit
  1437.           arithmetic by casting the character to an int.
  1438.     
  1439.                 int i;
  1440.                 char c;
  1441.                 ...
  1442.                 i += c;         /* Very efficent... B should be positive */
  1443.                 i += (int)c;    /* Less efficent... B can be negative */
  1444.     
  1445.              Read the notes at the end of the section  entitled  "Structures
  1446.           and Unions" for information on  limitations  or  differences  from
  1447.           standards  'C'  in  MICRO-C's  implementation  of  structures  and
  1448.           unions.
  1449.     MICRO-C                                                          Page: 30
  1450.  
  1451.  
  1452.     4. ADVANCED TOPICS
  1453.     
  1454.           This section provides information on the more advanced aspects  of
  1455.        MICRO-C, which  is  generally  not  needed  for  casual  use  of  the
  1456.        language.
  1457.     
  1458.        4.1 Conversion Rules
  1459.     
  1460.              MICRO-C keep track of the "type" of  each  value  used  in  all
  1461.           expressions. This type identifies certain characteristics  of  the
  1462.           value,  such  as   size   range   (8/16   bits),   numeric   scope
  1463.           (signed/unsigned), reference (value/pointer) etc.
  1464.     
  1465.              When an  operation  is  performed  on  two  values  which  have
  1466.           identical "types", MICRO-C assigns that same "type" to the result.
  1467.     
  1468.              When the  two  value  "types"  involved  in  an  operation  are
  1469.           different, MICRO-C calculates the "type" of the result  using  the
  1470.           following rules:
  1471.     
  1472.           4.1.1 Size range
  1473.     
  1474.                 If both values are  direct  (not  pointer)  references,  the
  1475.              result will be 8 bits only if  both  values  were  8  bits.  If
  1476.              either value was 16 bits, the result will be 16 bits.
  1477.     
  1478.                 If one value is a pointer, and  the  other  is  direct,  the
  1479.              result will be a pointer to the same size value as the original
  1480.              pointer.
  1481.     
  1482.                 If both values were pointers, the result will be  a  pointer
  1483.              to 16 bits only if both original  pointers  referenced  16  bit
  1484.              values. If either pointer referenced an 8 bit value, the result
  1485.              will reference an 8 bit value.
  1486.     
  1487.           4.1.2 Numeric Scope
  1488.     
  1489.                 The result of an expression is considered to be signed  only
  1490.              if both original values were signed. If  either  value  was  an
  1491.              unsigned value, the result is unsigned.
  1492.     
  1493.           4.1.3 Reference
  1494.     
  1495.                 If either of the original values was a pointer,  the  result
  1496.              will be a pointer.
  1497.     
  1498.              Note that this "calculated" result type  is  used  for  partial
  1499.           results within an expression. Whenever a symbol such as a variable
  1500.           or function is referenced, the type of that symbol is  taken  from
  1501.           its declaration, no matter what "type" of value  was  last  stored
  1502.           (variable) or returned (function).
  1503.     
  1504.              The TYPECAST  operation  may  be  used  to  override  the  type
  1505.           calculated for the result of an expression if necessary.
  1506.     MICRO-C                                                          Page: 31
  1507.  
  1508.  
  1509.        4.2 Assembly Language Interface
  1510.     
  1511.              Assembly language programs may be called from 'C' functions and
  1512.           vice versa. These programs may be in the form of  inline  assembly
  1513.           language statements in the 'C' source code, or  separately  linked
  1514.           modules.
  1515.     
  1516.              When MICRO-C calls any routine ('C'  or  assembler),  it  first
  1517.           pushes all arguments to the routine onto the processor  stack,  in
  1518.           the order in  which  they  occur  in  the  argument  list  to  the
  1519.           function. This means that the LAST argument  to  the  function  is
  1520.           LOWEST on the processor stack.
  1521.     
  1522.              Arguments are always pushed as 16 bit values. Character  values
  1523.           are extended to 16 bits, and arrays are passed as 16 bit  pointers
  1524.           to the array. (MICRO-C knows that arrays which are  arguments  are
  1525.           actually  pointers,  and  automatically  references  through   the
  1526.           pointer).
  1527.     
  1528.              After pushing the arguments, MICRO-C then generates  a  machine
  1529.           language subroutine  call,  thereby  executing  the  code  of  the
  1530.           routine.
  1531.     
  1532.              Since the compiler uses the ACCUMULATOR and INDEX REGISTER,  it
  1533.           will automatically save them (if necessary) during  processing  of
  1534.           the arguments to the function (even if no arguments are  present),
  1535.           and therefore these registers do not have to be preserved  by  the
  1536.           called routine.
  1537.     
  1538.              NOTE that any other  registers  used  by  the  code  generation
  1539.           routines (register variables etc) will not be  saved  by  MICRO-C,
  1540.           and should be preserved by called functions if their content is to
  1541.           be relied on between function calls.
  1542.     
  1543.              Once the called routine returns, the arguments are removed from
  1544.           the stack by the calling program. This usually consists of  simply
  1545.           adding the number of  bytes  pushed  as  arguments  to  the  stack
  1546.           pointer.
  1547.     
  1548.              When the called function executes, the first thing usually done
  1549.           is to push any registers which must be preserved, and  to  reserve
  1550.           space on the stack for any local variables which are required.  In
  1551.           some implementations, a "base" register may also be established to
  1552.           provide a stable reference to the local variables and arguments.
  1553.     
  1554.              It is the responsibility of the called function to  remove  any
  1555.           saved registers and local variable space from the stack before  it
  1556.           returns. If a value is to be returned to the calling  program,  it
  1557.           is expected to be in the ACCUMULATOR register.
  1558.     MICRO-C                                                          Page: 32
  1559.  
  1560.  
  1561.              Local variables in a  function  may  be  referenced  as  direct
  1562.           offsets from the "base" register or stack pointer.  Note  that  if
  1563.           the stack pointer is used, offsets must be adjusted for the number
  1564.           of bytes which are pushed and  popped  on  the  stack  during  the
  1565.           execution of the function.
  1566.     
  1567.              The address of a particular local variable is calculated as:
  1568.     
  1569.                                 "base register"
  1570.                                        -
  1571.                      (Size of all local variables in bytes)
  1572.                                        + 
  1573.                (size of all preceeding local variables in bytes)
  1574.     
  1575.                                     -- OR --
  1576.     
  1577.                                 "stack pointer"
  1578.                                        +
  1579.                    (# bytes pushed during function execution)
  1580.                                        +
  1581.                (size of all preceeding local variables in bytes)
  1582.     
  1583.              Arguments to a  function  may  also  be  referenced  as  direct
  1584.           offsets from the "base" register or stack  pointer,  in  much  the
  1585.           same way as local variables are.
  1586.     
  1587.              The address of a particular argument is calculated as:
  1588.     
  1589.                                 "base register"
  1590.                                        +
  1591.         (# bytes pushed at entry of function to preserve registers etc.)
  1592.                                        +
  1593.                  (Size of return address on stack (usually 2))
  1594.                                        +
  1595.                       (# arguments from LAST argument) * 2
  1596.     
  1597.                                     -- OR --
  1598.     
  1599.                                 "stack pointer"
  1600.                                        +
  1601.                    (# bytes pushed during function execution)
  1602.                                        +
  1603.                      (size of all local variables in bytes)
  1604.                                        +
  1605.         (# bytes pushed at entry of function to preserve registers etc.)
  1606.                                        +
  1607.                  (Size of return address on stack (usually 2))
  1608.                                        +
  1609.                       (# arguments from LAST argument) * 2
  1610.     
  1611.              NOTE: The (number of bytes pushed at entry of  function)  is  a
  1612.           function of the code generator,  and  depends  on  the  particular
  1613.           MICRO-C implementation. Examine  some  assembly  output  from  the
  1614.           compiler to determine the actual number on your system.
  1615.     MICRO-C                                                          Page: 33
  1616.  
  1617.  
  1618.              If a function has been declared  as  "register",  MICRO-C  will
  1619.           load the accumulator with  the  number  of  arguments  which  were
  1620.           passed, each time the function is called. This allows the function
  1621.           to determine the location of the first argument.
  1622.     
  1623.              The address of  the  first  argument  passed  to  a  "register"
  1624.           function may be calculated as:
  1625.     
  1626.                            (accumulator contents) * 2
  1627.                                        + 
  1628.                                 "base register"
  1629.                                        +
  1630.         (# bytes pushed at entry of function to preserve registers etc.)
  1631.                                        +
  1632.                  (Size of return address on stack (usually 2))
  1633.     
  1634.                                     -- OR --
  1635.     
  1636.                            (accumulator contents) * 2
  1637.                                        +
  1638.                                 "stack pointer"
  1639.                                        +
  1640.                    (# bytes pushed during function execution)
  1641.                                        +
  1642.                      (size of all local variables in bytes)
  1643.                                        +
  1644.         (# bytes pushed at entry of function to preserve registers etc.)
  1645.                                        +
  1646.                  (Size of return address on stack (usually 2))
  1647.     
  1648.              Global  variables  exist  at  absolute  addresses  and  may  be
  1649.           referenced directly by name from within assembler  programs.  Keep
  1650.           in mind however, that MICRO-C uses only the first 15 characters of
  1651.           a symbol's name. Also, many code generators will reduce  the  size
  1652.           of names even further, often using an algorithm  to  compress  the
  1653.           name rather than simply truncating it. For this reason,  it  is  a
  1654.           good idea to avoid using global symbol names which are longer than
  1655.           8 characters if they are to be  referenced  from  within  assembly
  1656.           language programs.
  1657.     MICRO-C                                                          Page: 34
  1658.  
  1659.  
  1660.        4.3 Compiling for ROM
  1661.     
  1662.              Assuming  the  code  generator   does   not   employ   "tricky"
  1663.           programming techniques such as self  modifying  code,  the  output
  1664.           from the compiler is entirely "clean", and may be placed  in  Read
  1665.           Only Memory (ROM).
  1666.     
  1667.              The compiler places all initialized  global  variables  in  the
  1668.           output file as part of the code image. When the program is  stored
  1669.           in ROM, those variables are also stored in ROM, and  will  not  be
  1670.           modifiable.
  1671.     
  1672.              When the program is to be placed in ROM, you may not initialize
  1673.           any variables which you intend to modify  later.  Those  variables
  1674.           must be explicitly initialized by code executed at  the  beginning
  1675.           of the program.
  1676.     
  1677.              Initialized variables which you do not intend to  modify  (such
  1678.           as tables etc.) may be initialized in the declaration, and will be
  1679.           permanently saved in the ROM as part of the static code image.
  1680.     
  1681.              The  processor  stack  pointer  must  be  set  up  before   any
  1682.           expressions are evaluated, or any function  calls  are  performed.
  1683.           One way to do this is with inline assembly statements at  the  top
  1684.           of the file.
  1685.     
  1686.              All non-initialized global variables must be  located  in  RAM.
  1687.           The compiler usually outputs all such variables at the very end of
  1688.           the compilation, just after dumping the literal pool.  The  global
  1689.           variables may be moved to RAM by  editing  the  output  file,  and
  1690.           placing an appropriate "ORG" statement at  the  beginning  of  the
  1691.           globals.
  1692.     
  1693.              You must also be sure to relocate the temporary location  which
  1694.           is defined in the startup code and runtime library  ("?temp"),  as
  1695.           well  as  any  global  variables  used  in  the  standard  library
  1696.           functions.
  1697.     MICRO-C                                                          Page: 35
  1698.  
  1699.  
  1700.     5. THE MICRO-C COMPILER
  1701.     
  1702.           The heart of the MICRO-C programming environment is the  COMPILER.
  1703.        This program reads a  file  containing  a  'C'  source  program,  and
  1704.        translates it into an equivalent assembly language program.
  1705.     
  1706.           The compiler includes its  own  limited  pre-processor,  which  is
  1707.        suitable for  compiling  programs  requiring  only  non-parameterized
  1708.        MACRO substitution, simple INCLUDE file capability, and  single-level
  1709.        CONDITIONAL processing.
  1710.     
  1711.        5.1 The MCC command
  1712.     
  1713.              When  created  using  the  'io'  routines   supplied   on   the
  1714.           distribution disk, the format of the MICRO-C Compiler command line
  1715.           is:
  1716.     
  1717.                     MCC [input_file] [output_file] [options]
  1718.     
  1719.              [input_file] is the name of  the  source  file  containing  'C'
  1720.           statements to read. If no filenames are given, MCC will read  from
  1721.           standard input.
  1722.     
  1723.              [output_file] is the name of the file to  which  the  generated
  1724.           assembly language code is written. If less than two filenames  are
  1725.           specified, MCC will write to standard output.
  1726.     
  1727.           5.1.1 Command Line Options
  1728.     
  1729.                 -c      - Includes the 'C' source code in the output file
  1730.                           as assembly language comments.
  1731.     
  1732.                 -f      - Causes the compiler to "Fold" its literal pool.
  1733.                           (Identical strings not contained in explicit
  1734.                           variables only once in memory).
  1735.     
  1736.                 -l      - Enables MCC to accept line numbers.
  1737.                           (At beginning of line, followed by ':').
  1738.     
  1739.                 -q      - Instructs MCC to be quiet, and not display the
  1740.                           startup message when it is executed.
  1741.     MICRO-C                                                          Page: 36
  1742.  
  1743.  
  1744.     6. PORTING THE COMPILER
  1745.     
  1746.           There are two major goals to accomplish when porting  the  MICRO-C
  1747.        compiler to a new machine. The first is to make the compiler  run  in
  1748.        the new environment, and the second is to make it  produce  code  for
  1749.        that environment.
  1750.     
  1751.           These two goals do not always go hand in hand. For example, it may
  1752.        be desirable to implement a CROSS COMPILER which generates code for a
  1753.        different system from that on which it runs.
  1754.     
  1755.           The usual method of porting a compiler to system A when a  version
  1756.        of the compiler is already running on system B, is to first create  a
  1757.        compiler which runs on system B, producing code for  system  A.  This
  1758.        "new" compiler may then be used to create a compiler  which  runs  on
  1759.        system A.
  1760.     
  1761.           The compiler consists of a module "compile"  which  contains,  the
  1762.        main compiler, input scanner, regular expression parser,  and  symbol
  1763.        table management routines.  This  is  the  "static"  portion  of  the
  1764.        compiler which does not change in different implementations.
  1765.     
  1766.           To create a working compiler, the above module  must  be  compiled
  1767.        and linked with an "io" module and "code"  module.  The  "io"  module
  1768.        performs the necessary initialization and I/O to allow  the  compiler
  1769.        to run in a particular  environment  (goal  #1).  The  "code"  module
  1770.        generates  the  assembly  language  output  code  for  a   particular
  1771.        environment (goal #2).
  1772.     
  1773.           The compiler uses NO system library functions, and  relies  on  NO
  1774.        system services (other  than  those  used  by  the  "io"  and  "code"
  1775.        modules). This allows the compiler to  be  ported  to  virtually  any
  1776.        system.
  1777.     
  1778.           All fixed compiler  parameters  (such  as  table  sizes  etc)  are
  1779.        contained in the header file "compile.h".  When  porting  to  systems
  1780.        with very limited RAM (less than 64k), you may have to reduce some of
  1781.        these sizes in order to get it to fit.
  1782.     
  1783.        6.1 The "io" module
  1784.     
  1785.              The "io" module required  by  the  compiler  must  contain  the
  1786.           following function definitions:
  1787.     
  1788.              The function "main()" is called by the  operating  system  when
  1789.           the MICRO-C compiler is executed. It is  responsable  for  parsing
  1790.           any parmeters and command qualifiers, opening the input and output
  1791.           files,  performing  any  other  initializations  that   might   be
  1792.           required, and then  invoking  the  function  "compile()"  with  no
  1793.           arguments. The program filename should also  be  copied  into  the
  1794.           array 'file_names' found in compile.c. The "compile"  function  is
  1795.           internal to the "compile.c" module, and  will  never  return.  For
  1796.           UNIX and other systems which support I/O redirection, "stdin"  and
  1797.           "stdout" are often used for the input and output files.
  1798.     MICRO-C                                                          Page: 37
  1799.  
  1800.  
  1801.              The function "terminate(rc)" is called when  the  compiler  has
  1802.           finished all processing and wishes to terminate. The value "rc" is
  1803.           a return code: 0 = Success, program compiled without error,  -1  =
  1804.           Compile was aborted due to severe errors, n  =  Compile  finished,
  1805.           but had 'n' errors.
  1806.     
  1807.              The function "put_chr(chr, flag)"  is  passed  a  character  to
  1808.           output, as well as a flag. The flag will always be zero  when  the
  1809.           character is being sent to the console terminal, or non-zero  when
  1810.           the character is to be written to the output file.
  1811.     
  1812.              The function "put_str(*ptr, flag)" is passed  a  pointer  to  a
  1813.           zero terminated string, which is to be written to the  console  or
  1814.           output file as determined by "flag".
  1815.     
  1816.              The function "put_num(number, flag)" is passed a 16 bit number,
  1817.           which is to be written in printable form to the console or  output
  1818.           file as determined by "flag".
  1819.     
  1820.              The function "get_lin(*ptr)" is passed a pointer to a character
  1821.           array, and should read a single line from the currently open input
  1822.           file into that array. The manifest definition  "LINE_SIZE",  found
  1823.           in "compile.h" may be used to determine the  maximum  line  length
  1824.           acceptable to the compiler. Return of a non-zero  value  indicates
  1825.           the end of file condition.
  1826.     
  1827.              The function "f_open(*ptr)" is passed a pointer to a  filename.
  1828.           The new file should be opened, and if successful,  the  old  input
  1829.           file should remain open and be "stacked", so that it can be  later
  1830.           returned to, and a non-zero value returned. A zero value indicates
  1831.           to the compiler that the file could not be opened.
  1832.     
  1833.              The  function  "f_close()"  is  responsible  for  closing   the
  1834.           currently  open  input  file,  and  returning  to  the   "stacked"
  1835.           previously open one. It receives  no  parameters.  Note:  multiple
  1836.           "opens"  may  be  stacked  -  see  the  manifest   definition   of
  1837.           "INCL_DEPTH" in the "compile.h" file.
  1838.     
  1839.           6.1.1 Notes on I/O module
  1840.     
  1841.              1) It is the responsibility of the "put" routines to  translate
  1842.                 the  NEWLINE  '\n'  (0x0a)  character  into  whatever   line
  1843.                 termination  character(s)  are  required   by   the   target
  1844.                 operating system.
  1845.     
  1846.              2) If unix "stdin"  and  "stdout"  are  not  used,  it  is  the
  1847.                 responsibility  of  "main"  to  display  appropriate   error
  1848.                 messages if the input or output files could not be opened.
  1849.     
  1850.                 Refer to  the  sample  "io"  modules  distributed  with  the
  1851.              compiler.
  1852.     MICRO-C                                                          Page: 38
  1853.  
  1854.  
  1855.        6.2 The "code" module
  1856.     
  1857.              In order to insure that MICRO-C is portable  to  virtually  any
  1858.           environment,  the  compiler  makes  few  assumptions   about   the
  1859.           processor or system software of  the  target  system.  The  "code"
  1860.           module is relied  on  to  produce  all  machine  instructions  and
  1861.           assembler directives written to the output file.
  1862.     
  1863.              The only two real "assumptions" made about the target processor
  1864.           are:
  1865.     
  1866.           1) It is assumed that the target processor  has  an  "accumulator"
  1867.              register in which all math operations are performed,  and  that
  1868.              the  lower  8  bits  of   this   register   may   be   accessed
  1869.              independantly.
  1870.     
  1871.           2) It is  assumed  that  the  target  processor  has  one  "index"
  1872.              register which may be loaded with a  16  bit  value,  and  that
  1873.              memory references may be made indirectly through this register.
  1874.     
  1875.              If the target processor does not support the above features, it
  1876.           may be possible to write a code generator for it using some  other
  1877.           features of the processor.
  1878.     
  1879.              For example, if an "index" register  does  not  exist,  it  may
  1880.           often be implemented using two bytes of reserved memory.
  1881.     
  1882.              The code  generation  module  required  by  the  compiler  must
  1883.           contain the following function definitions:
  1884.     
  1885.              The function  "do_comment(*ptr)"  is  passed  a  pointer  to  a
  1886.           character string, which is should write to the output  file  as  a
  1887.           single line COMMENT (used by '-c' option). This function  is  also
  1888.           called with a NULL (0)  pointer  anytime  the  compiler  wants  to
  1889.           insure that the code generator is reset to begin  a  new  line  of
  1890.           output.
  1891.     
  1892.              The function "do_asm(*ptr)" is passed a pointer to a  character
  1893.           string, which it should write to the output file as a single  line
  1894.           STATEMENT (used for inline assembly language).
  1895.     
  1896.              The function "def_module()"  is  called  at  the  beginning  of
  1897.           compilation, before any other code generator functions are called.
  1898.           It is used to output any pre-amble needed by the assembler.
  1899.     
  1900.              The function "end_module()"  is  called  at  the  very  end  of
  1901.           compilation, and is the last code generator function called. It is
  1902.           used to output any post-amble needed by the assembler.
  1903.     MICRO-C                                                          Page: 39
  1904.  
  1905.  
  1906.              The function "def_static(symbol)" is passed am index  into  the
  1907.           compiler symbol tables for a global variable, which is about to be
  1908.           initialized as static storage. The call to this function  will  be
  1909.           immediately followed by a call to "init_static" or "end_static".
  1910.     
  1911.              The "init_static(token, value,  word)"  function  is  passed  a
  1912.           token and value, with which it should initialize a single  element
  1913.           of static storage. The "word" flag will be non-zero if  the  value
  1914.           is a 16 bit element. Only the "constant" tokens  (NUMBER,  STRING,
  1915.           LABEL) and SYMBOL need be handled by this routine. When SYMBOL  is
  1916.           used,  the  constant  ADDRESS  of  the  passed  symbol  should  be
  1917.           generated.
  1918.     
  1919.              The  "end_static()"  function  is  called  to   terminate   the
  1920.           definition of static storage.
  1921.     
  1922.              NOTE: "init_static"  should  not  rely  on  "def_static"  being
  1923.           called first,  since  it  is  also  called  immediately  following
  1924.           "def_label" to define "switch" tables (See "do_switch"). After the
  1925.           table  is  defined,  the  compiler  will  call  "end_static()"  to
  1926.           terminate the initialization and set up for the next.
  1927.     
  1928.              The function "def_global(symbol, size)" is called at the end of
  1929.           the compile, once for each non-static global  variable  which  was
  1930.           defined. The "size" paremeter indicates the  number  of  BYTES  of
  1931.           memory to be reserved for that variable.
  1932.     
  1933.              The function "def_extern(symbol)" is called at the end  of  the
  1934.           compile, once  for  each  unresolved  external  symbol  which  was
  1935.           defined. This routine should examine the type of  the  symbol  and
  1936.           output the appropriate assembler directives  to  allow  it  to  be
  1937.           referenced in another module.
  1938.     
  1939.              The "def_func(symbol, size)"  routine  is  called  to  start  a
  1940.           function definition. The "symbol" parameter is an index  into  the
  1941.           compiler symbol tables for the function entry being  defined.  The
  1942.           "size" parameter indicates how many  bytes  of  memory  should  be
  1943.           allocated  on  the  stack  for  local  variables.  When   defining
  1944.           "register" functions, care must  be  taken  that  the  entry  code
  1945.           preserves the contents of the accumulator.
  1946.     
  1947.              The "end_func()" routine is  called  to  terminate  a  function
  1948.           definition.  It  should  remove  anything  placed  on  the   stack
  1949.           (including the local variable space allocated by "def_func"),  and
  1950.           terminate the function with a "return" instruction.
  1951.     
  1952.              The "def_label(label)" function is called whenever the compiler
  1953.           wants to generate a label in the output file. Each label generated
  1954.           by the compiler is identified by a 16 bit unsigned number.  It  is
  1955.           up to the code generator to generate a unique label  suitable  for
  1956.           the target assembler.
  1957.     MICRO-C                                                          Page: 40
  1958.  
  1959.  
  1960.              The "def_literal(*ptr, size)" function is called at the end  of
  1961.           the  compile,  just  before  non-initialized  global  symbols  are
  1962.           generated. This routine is  given  a  pointer  to  the  compiler's
  1963.           "literal pool", which contains all the character strings  occuring
  1964.           during the compilation. The "size" parameter  indicates  how  many
  1965.           characters are in the pool. This pool must  be  generated  in  the
  1966.           output file as a string of byte constants.
  1967.     
  1968.              The "call(token, value,  type,  clean)"  function  is  used  to
  1969.           generate  a  machine  language  subroutine  call  to  the   entity
  1970.           indicated by the "token, value & type" parameters (See later). The
  1971.           "clean" parameter indicates how many entries were pushed onto  the
  1972.           stack as arguments, which should be removed following the function
  1973.           call.  Note:  Since  stack  entries  are   TWO   bytes   in   most
  1974.           implementations, the "clean" value must be multiplied  by  two  to
  1975.           get the actual number of bytes to be removed from the stack.
  1976.     
  1977.              The function "jump(label,  ljmp)"  is  called  to  generate  an
  1978.           unconditional jump instruction to the indicated compiler generated
  1979.           label. The "ljmp" flag will be set to zero if the jump  references
  1980.           code within the same expression from which it  is  generated,  and
  1981.           non-zero if one or more statements may occur between the jump  and
  1982.           the destination label. This allows  the  code  generator  to  take
  1983.           advantage of "short" jumps if they are available on the target.
  1984.     
  1985.              The function "jump_if(cond, label, ljmp) is called to  generate
  1986.           a conditional jump to a compiler generated label. The "cond" value
  1987.           indicates the condition: FALSE = Jump if accumulator is zero, TRUE
  1988.           = jump if accumulator is non-zero. Remaining  parameters  are  the
  1989.           same as above.
  1990.     
  1991.              The function "do_switch(label)" is  passed  the  address  of  a
  1992.           "switch" table, which contains 16  bit  entries,  and  is  of  the
  1993.           following format:
  1994.     
  1995.                         label-1, value-1, label-2, value-2, ....
  1996.                         label-n, value-n, 0, default_label
  1997.     
  1998.              This routine should search the table for the value currently in
  1999.           the accumulator, and if found, it  should  proceed  to  the  label
  2000.           associated with that value. If the value is not found  before  the
  2001.           end of the table is encountered (identified by a  label  value  of
  2002.           zero), execution should  proceed  at  the  address  identified  by
  2003.           "default_label".
  2004.     
  2005.              The "index_ptr(token, value, type)"  routine  should  load  the
  2006.           index register with the value  of  the  entity  indicated  by  the
  2007.           "token, value & type" parameters. This will always  be  a  16  bit
  2008.           wide quantity.
  2009.     MICRO-C                                                          Page: 41
  2010.  
  2011.  
  2012.              The "index_adr(token, value, type)"  routine  should  load  the
  2013.           index register with the 16 bit address of the  object  represented
  2014.           by "token, value & type". The only tokens passed to  this  routine
  2015.           are SYMBOL and ION_STACK.
  2016.     
  2017.              The routine "expand(type)" is called following  the  evaluation
  2018.           of expressions in "return" and "switch" statements, and is used to
  2019.           insure that the result is a 16 bit value.
  2020.     
  2021.              The routine "accop(oper, type)" is  called  to  perform  a  "no
  2022.           operand" operation on the accumulator. See "compile.h" for a  list
  2023.           of these operations. The "type" passed indicates the type of value
  2024.           expected as a result.
  2025.     
  2026.              The routine "accval(oper, rtype, token, value, type)" is called
  2027.           to perform a "one  operand"  operation  on  the  accumulator.  See
  2028.           "compile.h" for a list of these operations. "rtype" indicates  the
  2029.           type of value expected as a result. "token",  "value"  and  "type"
  2030.           indicate  the  location  and  type  of  operand  which  is   being
  2031.           processed.
  2032.     MICRO-C                                                          Page: 42
  2033.  
  2034.  
  2035.           6.2.1 Notes on code generation
  2036.     
  2037.                 The meaning of the individual bits  in  the  16  bit  "type"
  2038.              value which is passed to many of the code generation  routines,
  2039.              is documented in the "compile.h" file.
  2040.     
  2041.                 The meaning of "token"  is  documented  in  the  "compile.h"
  2042.              file. For  each  type  of  "token",  "value"  has  a  different
  2043.              meaning:
  2044.     
  2045.                 Token           Meaning of "value"
  2046.                 ----------------------------------------------------------
  2047.                 NUMBER          The numeric value of the constant.
  2048.                 STRING          The offset into the literal pool.
  2049.                 LABEL           The value of the compiler generated label.
  2050.                 SYMBOL          Index into global symbol tables.
  2051.                 All others      Undefined.
  2052.     
  2053.                 When token is a SYMBOL, the "value" passed is used to  index
  2054.              into the global symbol tables (contained within  the  "compile"
  2055.              module) to  determine  information  about  the  variable.  When
  2056.              "value" is  less  than  the  value  of  the  compiler  internal
  2057.              variable 'global_top', the symbol is GLOBAL,  otherwise  it  is
  2058.              LOCAL:
  2059.     
  2060.                 s_name[value]   - Name of symbol (up to SYMBOL_SIZE chars)
  2061.                 s_type[value]   - Type of symbol (bits defined in "compile.h").
  2062.                 s_index[value]  - Variable index:
  2063.                         Local (auto):   Stack offset from def_func.
  2064.                         Argument:       Stack offset from last argument pushed.
  2065.                         Static:         Unique variable number for symbol.
  2066.     
  2067.                 When calculating the stack offset for  ARGUMENTs,  you  must
  2068.              add the number of bytes placed on the stack when  the  function
  2069.              was called. This  includes  the  local  variables,  the  return
  2070.              address, and any other values that "def_func" might push.
  2071.     
  2072.                 There are two popular ways of  providing  addressability  to
  2073.              local variables:
  2074.     
  2075.                 If the processor has many registers, you can reserve one  as
  2076.              a "base" pointer, and point it at the top of the stack when the
  2077.              function  is  entered.  This  allows  local  variables  to   be
  2078.              referenced as negative offsets from that "base"  register,  and
  2079.              arguments to be referenced as positive offsets  from  it.  This
  2080.              approach also allows the stack to  be  restored  directly  from
  2081.              this base  register  when  the  function  terminates.  See  the
  2082.              section on assembly language interfacing.
  2083.     
  2084.                 Another approach is to have the  code  generator  "remember"
  2085.              exactly how many bytes have been pushed onto  the  stack  since
  2086.              "def_func", and adjust the offsets it generates  based  on  the
  2087.              stack contents. This has  the  advantage  of  not  tying  up  a
  2088.              register.
  2089.     MICRO-C                                                          Page: 43
  2090.  
  2091.  
  2092.                 If you intend to use the MICRO-C Source Linker (SLINK), then
  2093.              you have to insure that whatever variable you use to  reference
  2094.              the "literal pool" qualifies as a "compiler  generated"  label,
  2095.              allowing SLINK to adjust it when processing the  source  files.
  2096.              Compiler  generated  labels  normally  consist  of   a   single
  2097.              character (such as '?'), followed by a  decimal  number.  Since
  2098.              the compiler begins generating its labels with the  value  '1',
  2099.              you may safely use '0' as the literal pool variable (Ie: '?0').
  2100.     
  2101.                 It is the responsibility of the code generator to keep track
  2102.              of the validity  of  the  upper  8  bits  of  the  accumulator.
  2103.              Appropriate sign extension or clearing of  high  bits  must  be
  2104.              performed as necessary to convert signed and unsigned character
  2105.              values when 16 bit results when required.
  2106.     
  2107.                 To improve the effiency of conditional statements, the  code
  2108.              generator should keep track of the validity of the "zero"  flag
  2109.              in  the  processor's  condition  code  register,  and  generate
  2110.              appropriate  "test"  instructions  only  if  necessary  when  a
  2111.              conditional jump is compiled.
  2112.     
  2113.                 For  processors  not  supporting   operations   with   stack
  2114.              contents, the "ON_STACK" and "ION_STACK" tokens may implemented
  2115.              by first popping the top of the  stack  into  a  register.  The
  2116.              "ISTACK_TOP" token is a special case, because  the  address  on
  2117.              the top of the stack must  not  be  lost.  This  token  may  be
  2118.              efficiently implemented, because "ISTACK_TOP" is only used  for
  2119.              read/write operations to  a  stacked  calculated  address.  For
  2120.              example:
  2121.     
  2122.                             array1[i] += array2[i];
  2123.     
  2124.                 This statement calculates the address of "array1[i]" (in the
  2125.              index register). Since the "index" register is  again  used  in
  2126.              calculating the address of "array2[i]", the first "index"  will
  2127.              be placed on the stack. Once the contents  of  "array2[i]"  are
  2128.              retrieved, it  will  be  added  using  "ISTACK_TOP",  and  then
  2129.              re-stored using "ION_STACK".
  2130.     
  2131.                 The "ISTACK_TOP" token may  thus  pop  the  address  into  a
  2132.              register, and set a flag indicating to the code generator  that
  2133.              the next "ION_STACK" token  is  to  go  through  that  register
  2134.              rather than the top of the stack. Note that since an arithmetic
  2135.              operation may be performed between the two references, you must
  2136.              not use a register which is  modified  in  code  generated  for
  2137.              arithmetic operations.
  2138.     
  2139.                 Refer to the sample code  generators  distributed  with  the
  2140.              compiler.
  2141.     MICRO-C                                                          Page: 44
  2142.  
  2143.  
  2144.        6.3 The "compile" module
  2145.     
  2146.              The "compile" module  contains  the  main  statement  analyser,
  2147.           input  scanner,  expression  parser  and  symbol  table  managment
  2148.           routines for the MICRO-C compiler. This module is  common  to  all
  2149.           implementations, and should NOT require changes in most cases. The
  2150.           source code for this module is contained in the  "compile.c"  file
  2151.           on your distribution diskette, and may  be  examined  for  insight
  2152.           into the internal operation of the compiler.
  2153.     
  2154.              This module must be compiled and linked with your I/O and  code
  2155.           generation routines to  generate  a  complete  executable  MICRO-C
  2156.           compiler.
  2157.     
  2158.              To test your code generator,  the  file  "test.c"  is  provided
  2159.           which when compiled using the new compiler, performs a  number  of
  2160.           simple tests  to  verify  your  code  generator.  This  is  not  a
  2161.           comprehensive analysis, as  it  makes  no  assumptions  about  the
  2162.           processor, however, it provides a good indication that  your  code
  2163.           generator is on the right track.
  2164.     
  2165.              A number of fixed parameters to the  compiler  (such  as  table
  2166.           sizes etc.) are contained in the header file "compile.h". The most
  2167.           common reason for changing  these  parameters  is  to  reduce  the
  2168.           memory requirements, in order to get  MICRO-C  to  fit  into  very
  2169.           small systems.
  2170.     
  2171.              If any of the parameters in "compile.h" are to be changed,  you
  2172.           must  make  the  changes  BEFORE  compiling  any  of  the  modules
  2173.           (compile, io or codegen).
  2174.     
  2175.              The file  "tokens.h"  contains  symbolic  definitions  for  the
  2176.           tokens parsed by the  compiler,  the  text  of  which  is  in  the
  2177.           character array variable "tokens". If you make any changes to this
  2178.           token table, MAKE SURE that the contents of the "tokens"  variable
  2179.           and the "tokens.h" file agree, otherwise, you will end up  with  a
  2180.           compiler for a very strange language.
  2181.     
  2182.           6.3.1 **NOTE for 32 bit compiler users
  2183.     
  2184.                 COMPILE.C has one potential portability  problem  if  it  is
  2185.              compiled on a machine where  an  'int'  is  not  16  bits.  The
  2186.              routine "skip_comment()" uses a 16 bit 'int' to hold  the  last
  2187.              two characters from the source file, in order to test  for  the
  2188.              "/*" and "*/" sequences.
  2189.     
  2190.                 If an 'int' can contain more that TWO characters,  you  must
  2191.              modify this function so that only the last two  characters  are
  2192.              retained.
  2193.     MICRO-C                                                          Page: 45
  2194.  
  2195.  
  2196.        6.4 Porting without a linker
  2197.     
  2198.              It is possible to port MICRO-C using a system  which  does  not
  2199.           support a linker. To do this, you must concatinate all the  source
  2200.           files "compile.c", "code.c" and "io.c" into  one  large  file  (in
  2201.           that order), and compile them all as one program.
  2202.     
  2203.              When this is done, the ".h" include files need only be included
  2204.           once, and external definitions  of  variables  occuring  in  other
  2205.           source files should not  be  used.  The  source  programs  on  the
  2206.           distribution disk all contain conditional  compilation  statements
  2207.           (#ifndef), which only perform the necessary #include and  external
  2208.           definition statements when compiling as a single file.
  2209.     
  2210.        6.5 Optimization Techniques
  2211.     
  2212.              The MICRO-C compiler performs the following machine independant
  2213.           optimizations of the output file:
  2214.     
  2215.           1) All constant expressions are evaluated  at  compile  time,  and
  2216.              expressed as a single constant value in the output code.
  2217.     
  2218.           2) Commutative operations may be reversed  to  take  advantage  of
  2219.              partial results  already  in  the  accumulator.  This  includes
  2220.              operations which have an equivalent reverse (ie: "a>(b-1)"  may
  2221.              become "(b-1)<a").
  2222.     
  2223.           3) Redundant jumps as a result of "return" or  "break"  statements
  2224.              are suppressed.
  2225.     
  2226.           4) The sense of jumps in conditional statements are  reversed  for
  2227.              logically negated expressions, code for '!' is  only  generated
  2228.              if the value returned by that operator is actually used.
  2229.     
  2230.           5) Jumps between code generated within  a  single  expression  are
  2231.              flagged as "short".
  2232.     
  2233.              Although the MICRO-C compiler produces fairly  reasonable  code
  2234.           for the  processor  model  it  uses,  that  model  is  necessarily
  2235.           limited, in order that it might fit a  large  number  of  physical
  2236.           targets. There are  several  simple  optimizations  which  may  be
  2237.           performed to further enhance the code generated by the compiler in
  2238.           a specific implementation.
  2239.     MICRO-C                                                          Page: 46
  2240.  
  2241.  
  2242.           6.5.1 Register Usage
  2243.     
  2244.                 MICRO-C assumes a single accumulator,  and  a  single  index
  2245.              register.  Additional  terms  in  complicated  expressions  are
  2246.              handled by placing temporary results on  the  processor  stack,
  2247.              and re-using those registers. All data placed on the  stack  is
  2248.              accessed on a "last in - first out" basis.
  2249.     
  2250.                 If the target processor has a  full  compliment  of  general
  2251.              purpose registers, an optimization may be performed  by  simply
  2252.              selecting another general purpose register as  the  accumulator
  2253.              or index register instead of placing the value  on  the  stack.
  2254.              The code generator must  keep  track  of  the  order  in  which
  2255.              registers are selected, and which register represents the "top"
  2256.              of the stack. If the number  of  values  "pushed"  exceeds  the
  2257.              number of available registers, the "oldest" register should  be
  2258.              placed on the stack, thereby allowing it to be re-used.
  2259.     
  2260.           6.5.2 Jump Optimization
  2261.     
  2262.                 Although MICRO-C identifies jumps to instructions which span
  2263.              more than one expression as "long",  often  the  addresses  are
  2264.              close enough together that short jumps may  actually  be  used.
  2265.              This optimization is particularily useful for  processors  such
  2266.              as the 8086, which does not support "long"  conditional  jumps,
  2267.              and therefore must simulate them with a short conditional  jump
  2268.              of the opposite sense around a long unconditional jump.
  2269.     
  2270.           6.5.3 Redundant Load Elimination
  2271.     
  2272.                 Since  MICRO-C  evaluates  and  processes   each   statement
  2273.              individually, it  does  not  carry  partial  results  from  one
  2274.              statement to another.
  2275.     
  2276.                 Consider the following statements:
  2277.     
  2278.                                  a = x;
  2279.                                  b = a + 1;
  2280.     
  2281.                 MICRO-C generates the code:
  2282.     
  2283.                                  LOAD x
  2284.                                  STORE a
  2285.                                  LOAD a
  2286.                                  ADD 1
  2287.                                  STORE b
  2288.     
  2289.                 An optimization may be performed  by  recognizing  that  the
  2290.              second "load" instruction is redundant, and can be  eliminated.
  2291.              Note: A more efficent (but less readable)  way  of  coding  the
  2292.              above statements which would result in the latter code  without
  2293.              optimization is:
  2294.     
  2295.                                  b = (a = x) + 1;
  2296.     MICRO-C                                                          Page: 47
  2297.  
  2298.  
  2299.           6.5.4 Peephole Optimization
  2300.     
  2301.                 Consider the statement:
  2302.     
  2303.                                  a = *++ptr;
  2304.     
  2305.                 MICRO-C generates the code:
  2306.     
  2307.                                  LOAD ptr
  2308.                                  INCREMENT
  2309.                                  STORE ptr
  2310.                                  MOVE ACCUMULATOR TO INDEX
  2311.                                  LOAD [INDEX]
  2312.                                  STORE a
  2313.     
  2314.                 For a processor supporting  a  rich  set  of  direct  memory
  2315.              addressing modes, the above sequence can be shortened to:
  2316.     
  2317.                                  INCREMENT_MEMORY ptr
  2318.                                  LOAD [ptr]
  2319.                                  STORE a
  2320.     
  2321.                 One of the most  successful  techniques  of  optimizing  the
  2322.              output code is also one of the simplest.  Known  as  "peephole"
  2323.              optimization, the method consists of keeping a  window  of  the
  2324.              last few instructions generated,  and  scanning  the  list  for
  2325.              known patterns every time a new instruction is added to it.
  2326.     
  2327.                 As long as the instructions in the list at  least  partially
  2328.              match one or more  of  the  "predefined"  patterns,  additional
  2329.              instructions are collected  until  either  a  complete  pattern
  2330.              match occurs, or all known patterns are eliminated.
  2331.     
  2332.                 If no matches occur, the "oldest" instruction is written  to
  2333.              the output file, and the next one  becomes  the  first  in  the
  2334.              "window".
  2335.     
  2336.                 Whenever a pattern is discovered, it is replaced  by  a  new
  2337.              series of instructions which perform the same function, but  in
  2338.              a more efficent manner.
  2339.     
  2340.                 The new instruction sequences  are  replaced  on  the  list,
  2341.              which may then be  again  scanned,  allowing  further  possible
  2342.              reductions to be discovered.
  2343.     
  2344.                 Handling of labels in the "window" and  their  corresponding
  2345.              placement in the output file must be carefully done,  in  order
  2346.              to preserve the "logical" context of the original code.
  2347.     MICRO-C                                                          Page: 48
  2348.  
  2349.  
  2350.     7. THE MICRO-C PREPROCESSOR
  2351.     
  2352.           The MICRO-C Preprocessor is a source code filter,  which  provides
  2353.        greater capabilities than the preprocessor which is integral  to  the
  2354.        MICRO-C compiler. It has been implemented as a  stand  alone  utility
  2355.        program which processes the source code before it is compiled.
  2356.     
  2357.           Due to the higher complexity of  this  preprocessor,  it  operates
  2358.        slightly slower than the the integral MICRO-C preprocessor.  This  is
  2359.        mainly due to the fact that it reads each line from the file and then
  2360.        copies it to a new line while performing the macro substitution. This
  2361.        is necessary since each macro may contain parameters  which  must  be
  2362.        replaced "on the fly" when it is referenced.
  2363.     
  2364.           The integral MICRO-C preprocessor is very FAST,  because  it  does
  2365.        not copy the input line. When it encounters a '#define'd  symbol,  it
  2366.        simply adjusts the input scanner pointer to point to  the  definition
  2367.        of that symbol.
  2368.     
  2369.           Keeping the extended preprocessor as a stand alone utility  allows
  2370.        you  to  choose  between  greater   MACRO   capability   and   faster
  2371.        compilation. It also allows the system to continue  to  run  on  very
  2372.        small hardware platforms.
  2373.     
  2374.           The additional capabilities of the extended preprocessor are:
  2375.     
  2376.             - Parameterized MACROs.
  2377.     
  2378.             - Multiple line MACRO's.
  2379.     
  2380.             - Nested conditionals.
  2381.     
  2382.             - Ability to undefine MACRO symbols.
  2383.     
  2384.             - Library reference in include file names.
  2385.     MICRO-C                                                          Page: 49
  2386.  
  2387.  
  2388.        7.1 The MCP command
  2389.     
  2390.              The format of the MICRO-C Preprocessor command line is:
  2391.     
  2392.                     MCP [input_file] [output_file] [options]
  2393.     
  2394.              [input_file] is the name of  the  source  file  containing  'C'
  2395.           statements to read. If no filenames are given, MCP will read  from
  2396.           standard input.
  2397.     
  2398.              [output_file] is the name of the file to  which  the  processed
  2399.           source code is written. If less than two filenames are  specified,
  2400.           MCP will write to standard output.
  2401.     
  2402.           7.1.1 Command Line Options
  2403.     
  2404.                 MCP accepts the following command line [options]:
  2405.     
  2406.                 -c      - Instructs MCP to keep comments from  the input
  2407.                           file (except for those in '#' statements which
  2408.                           are always removed). Normally, MCP will remove
  2409.                           all comments.
  2410.     
  2411.                 -l      - Causes the output file to contain line numbers.
  2412.                           Each line in the output file will be  prefixed
  2413.                           with the line number of the  originating  line
  2414.                           from the input file.
  2415.     
  2416.                 l=path  - Defines the directory path which will be taken
  2417.                           to reference  "library"  files when  '<>'  are
  2418.                           used around an  '#include'  file name.  Unless
  2419.                           otherwise specified, the path defaults to:
  2420.                                         '\mc'
  2421.     
  2422.                 -q      - Instructs MCP to be quiet, and not display the
  2423.                           startup message when it is executed.
  2424.     
  2425.           <name>=<text> - Pre-defines a non-parameterized macro  of  the
  2426.                           specified <name> with the string value <text>.
  2427.     MICRO-C                                                          Page: 50
  2428.  
  2429.  
  2430.        7.2 Preprocesor Commands
  2431.     
  2432.              The following commands are recognized by the MCP utility,  only
  2433.           if they occur at the beginning of the source file line:
  2434.     
  2435.           7.2.1 #define <name>(parameters) <replacement text>
  2436.     
  2437.                 Defines a global macro name which will be replaced with  the
  2438.              indicated <replacement text> wherever it occurs in  the  source
  2439.              file.
  2440.     
  2441.                 Macro  names  may  be  any  length,  and  may  contain   the
  2442.              characters 'a'-'z', 'A'-'Z', '0'-'9' and '_'.  Names  must  not
  2443.              begin with the characters '0'-'9'.
  2444.     
  2445.                 If the macro name is IMMEDIATELY followed by a list of up to
  2446.              10 parameter names contained in brackets, those parameter names
  2447.              will be substituted with parameters passed to the macro when it
  2448.              is referenced. Parameter names follow the same rules  as  macro
  2449.              names.
  2450.     
  2451.                      eg: #define min(a, b) (a < b ? a : b)
  2452.     
  2453.                 If any spaces exist between the macro name and  the  opening
  2454.              '(', the macro will not be  parameterized,  and  all  following
  2455.              text (including '(' and ')') will be  entered  into  the  macro
  2456.              definition.
  2457.     
  2458.                 If the very last character of a  macro  definition  line  is
  2459.              '\', MCP will continue the definition with the next  line  (The
  2460.              '\' is not included). Pre-processor statements included as part
  2461.              of a macro definition will not be processed by MCP, but will be
  2462.              passed on and handled by the integral MICRO-C preprocessor.
  2463.     
  2464.           7.2.2 #undef <symbol>
  2465.     
  2466.                 Undefines the named macro symbol. further references to this
  2467.              symbol will not be replaced.
  2468.     
  2469.                 NOTE: With MCP, macro definitions operate on a STACK. IE: If
  2470.              you define a macro  symbol,  and  then  re-define  it  (without
  2471.              '#undef'ing it first), subsequently '#undef'ing it  will  cause
  2472.              it to revert to its  previous  definition.  A  second  '#undef'
  2473.              would then cause it to be completely undefined.
  2474.     MICRO-C                                                          Page: 51
  2475.  
  2476.  
  2477.           7.2.3 #forget <symbol>
  2478.     
  2479.                 Similar  to  '#undef',  except  that  the  symbol  and   ALL
  2480.              SUBSEQUENTLY DEFINED SYMBOLS will be undefined.
  2481.     
  2482.                 Useful for releasing any local symbols (used only  within  a
  2483.              single include file).
  2484.     
  2485.                 For example:
  2486.     
  2487.                         #define GLOBAL "xxx"    /* first global symbol */
  2488.                             ...                 /* more globals */
  2489.                         #define LOCAL   "xxx"   /* first local symbol */
  2490.                             ...                 /* more locals */
  2491.                         /* body of include file goes here */
  2492.                         #forget LOCAL           /* release locals */
  2493.     
  2494.           7.2.4 #ifdef <symbol>
  2495.     
  2496.                 Causes the following lines (up to '#else' of '#endif') to be
  2497.              processed and included in the source file  only  if  the  named
  2498.              symbol is defined as a macro.
  2499.     
  2500.           7.2.5 #ifndef <symbol>
  2501.     
  2502.                 Causes the following lines (up to '#else' of '#endif') to be
  2503.              processed and included in the source file  only  if  the  named
  2504.              symbol is NOT defined as a macro.
  2505.     
  2506.                 NOTE: '#ifdef/#ifndef#else/#endif' may be nested.
  2507.     
  2508.           7.2.6 #else
  2509.     
  2510.                 Toggles the state of the "if_flag", controlling  conditional
  2511.              processing. Only has effect in the highest level  of  suspended
  2512.              processing. IE: Nested conditionals will work properly.
  2513.     
  2514.                 If the previous  '#ifdef/#ifndef'  failed,  processing  will
  2515.              begin again following the '#else'.
  2516.     
  2517.                 If the previous '#ifdef/#ifndef' passed, processing will  be
  2518.              suspended until the '#endif' is encountered.
  2519.     
  2520.                 NOTE: Since '#else' acts as a toggle, it may be used outside
  2521.              of any '#ifdef/#ifndef' to unconditionally  suspend  processing
  2522.              up to '#endif'. You can also use multiple '#else's in a  single
  2523.              conditional,  to  swap  back  and  forth   between   true/false
  2524.              processing without re-testing the condition.
  2525.     
  2526.           7.2.7 #endif
  2527.     
  2528.                 Resets  the  "if_flag"  controlling  conditionals,   causing
  2529.              processing to resume. Only has effect in the highest  level  of
  2530.              suspended  processing.  IE:  Nested  conditionals   will   work
  2531.              properly.
  2532.     MICRO-C                                                          Page: 52
  2533.  
  2534.  
  2535.           7.2.8 #include <filename>
  2536.     
  2537.                 Causes MCP to open the named file and include  its  contents
  2538.              as part of the input source.
  2539.     
  2540.                 If the filename is contained within '"' characters, it  will
  2541.              be opened exactly as  specified,  and  (unless  it  contains  a
  2542.              directory path) will reference a file in the current directory.
  2543.     
  2544.                 If the filename is contained within the characters  '<'  and
  2545.              '>', it will be  prefixed  with  the  library  path  (See  'l='
  2546.              option), and will therefore reference a file  in  that  library
  2547.              directory. The default  library  directory  is  assumed  to  be
  2548.              '\mc'.
  2549.     
  2550.                 For example:
  2551.     
  2552.                         #include "header.h"     /* from current directory */
  2553.                         #include <stdio.h>      /* from library directory */
  2554.     MICRO-C                                                          Page: 53
  2555.  
  2556.  
  2557.        7.3 Error messages
  2558.     
  2559.              When MCP detects an error during processing of an include file,
  2560.           it displays an error message, which is preceeded by  the  filename
  2561.           and line number where the error occurs. If more than 10 errors are
  2562.           encountered, MCP will terminate.
  2563.     
  2564.              The following error messages are reported by MCP:
  2565.     
  2566.           7.3.1 Cannot open include file
  2567.     
  2568.                 A '#include' statement on the  indicated  line  specified  a
  2569.              file which could not be opened for reading.
  2570.     
  2571.           7.3.2 Invalid include file name
  2572.     
  2573.                 A '#include' statement on the  indicated  line  specified  a
  2574.              file  name  which  was  not  contained  within  '"'   or   '<>'
  2575.              characters.
  2576.     
  2577.           7.3.3 Invalid macro name
  2578.     
  2579.                 A '#define' statement on the indicated line contains a macro
  2580.              name which does not follow the name rules.
  2581.     
  2582.           7.3.4 Invalid macro parameter
  2583.     
  2584.                 A '#define' statement on the indicated line contains a macro
  2585.              parameter name which does not follow the name rules.
  2586.     
  2587.                 A reference to a macro does not have a proper ')'  character
  2588.              to terminate the parameter list.
  2589.     
  2590.           7.3.5 Too many errors
  2591.     
  2592.                 More  than  10  errors  has  been  encountered  and  MCP  is
  2593.              terminating.
  2594.     
  2595.           7.3.6 Too many macro definitions
  2596.     
  2597.                 MCP has encountered more '#define' statements  than  it  can
  2598.              handle.
  2599.     
  2600.           7.3.7 Too many macro parameters
  2601.     
  2602.                 A '#define' statement on the indicated line  specifies  more
  2603.              parameters to the macro than MCP can handle.
  2604.     
  2605.           7.3.8 Too many include files
  2606.     
  2607.                 MCP has encountered more nested '#include'  statements  than
  2608.              it can handle.
  2609.     MICRO-C                                                          Page: 54
  2610.  
  2611.  
  2612.           7.3.9 Undefined macro
  2613.     
  2614.                 A '#undef' or '#forget'  statement  on  the  indicated  line
  2615.              references a macro name which has not been defined.
  2616.     
  2617.           7.3.10 Unterminated comment
  2618.     
  2619.                 The END OF FILE has  been  encountered  while  processing  a
  2620.              comment.
  2621.     
  2622.           7.3.11 Unterminated string
  2623.     
  2624.                 A quoted string  on  the  indicated  line  has  no  end.  To
  2625.              continue a string to  the  next  line,  use  '\'  as  the  last
  2626.              character on the line. The '\' will  not  be  included  in  the
  2627.              string.
  2628.     MICRO-C                                                          Page: 55
  2629.  
  2630.  
  2631.     8. THE MICRO-C OPTIMIZER
  2632.     
  2633.           The MICRO-C optimizer is an output code filter which examines  the
  2634.        assembly code produced by the compiler, recognizing known patterns of
  2635.        inefficent code (using the "peephole" technique), and  replaces  them
  2636.        with more optimal code  which  performs  the  same  function.  It  is
  2637.        entirely table driven, allowing it to be modified for  virtually  any
  2638.        processor.
  2639.     
  2640.           Due its many table lookup operations, the  optimizer  may  perform
  2641.        quite slowly when processing a large  file.  For  this  reason,  most
  2642.        people prefer not to optimize during the debugging of a program,  and
  2643.        utilize the optimizer only when creating the final copy.
  2644.     
  2645.        8.1 The MCO command
  2646.     
  2647.              The format of the MICRO-C Optimizer command line is:
  2648.     
  2649.                     MCO [input_file] [output_file] [options]
  2650.     
  2651.              [input_file] is the name of the source file containing assembly
  2652.           statements to read. If no filenames are given, MCO will read  from
  2653.           standard input.
  2654.     
  2655.              [output_file] is the name of the file to  which  the  optimized
  2656.           assembly  code  is  written.  If  less  than  two  filenames   are
  2657.           specified, MCO will write to standard output.
  2658.     
  2659.           8.1.1 Command Line Options
  2660.     
  2661.                 MCO accepts the following command line [options]:
  2662.     
  2663.                 -d      - Instructs MCO to produce a 'debug' display on
  2664.                           standard output showing the  source code  which
  2665.                           it is removing and replacing in the input file.
  2666.                           NOTE: If you do not specify an  explict  output
  2667.                                 file, you will get the  debug  statements
  2668.                                 intermixed with  the  optimized  code  on
  2669.                                 standard output.
  2670.     
  2671.                 -q      - Instructs  MCO  to be quiet,  and not display
  2672.                           the startup message when it is executed.
  2673.     MICRO-C                                                          Page: 56
  2674.  
  2675.  
  2676.        8.2 Porting MCO to a new processor
  2677.     
  2678.              The MICRO-C Optimizer is completely table driven, and is fairly
  2679.           easy to port to new processors.
  2680.     
  2681.              The peephole optimization table  is  called  'peep_table',  and
  2682.           consists of two  sequential  character  string  entries  for  each
  2683.           optimization, and is terminated by single NULL pointer.
  2684.     
  2685.              The first is the "take" entry, and  represents  an  instruction
  2686.           sequence which (if found) is to be removed from the  output  file.
  2687.           The second  is  the  "give"  entry,  and  defines  a  sequence  of
  2688.           instructions to be placed in the output file at that  point.  NOTE
  2689.           that due to the way the optimizer removes and replaces instruction
  2690.           in the circular "peephole" buffer, the instructions in the  "give"
  2691.           entry ARE CODED IN REVERSE ORDER.
  2692.     
  2693.              Characters in the "take" entry with the high  bit  set  ('\200'
  2694.           and higher) are special characters which  represent  any  variable
  2695.           string which may occur in the instruction sequence,  and  will  be
  2696.           replaced with the same string wherever that  character  occurs  in
  2697.           the "give" entry. If  the  same  special  character  (eg:  '\200')
  2698.           occurs more than once  in  the  "take"  entry,  the  corresponding
  2699.           strings must be exactly the same or else the entire sequence  will
  2700.           not be matched.
  2701.     
  2702.              There may be up to 8 different  such  variable  strings  within
  2703.           each entry, the lower three bits  ('\201'-\'207')  indicate  which
  2704.           variable is referenced.
  2705.     
  2706.              The 4'th bit ('\21x') when used in a  "take"  entry,  allows  a
  2707.           match only if the variable string contains only the numeric digits
  2708.           ('0'-'9'). If any other character occurs, the instruction sequence
  2709.           will not be matched. This bit has no effect when used in a  "give"
  2710.           entry.
  2711.     
  2712.              The 5'th bit ('\22x') causes  the  variable  string  to  access
  2713.           through the "complement" table (see later). When used in a  "take"
  2714.           entry, this bit allows a match only if the variable string  occurs
  2715.           in  that  table.  When  used  in  a  "give"  entry,   causes   the
  2716.           complementary string to be output from the table.
  2717.     
  2718.              The processor will stop scanning  a  variable  string  when  it
  2719.           encounters the character which  immediately  follows  the  special
  2720.           character in the "take" entry, or at the end of the input line.
  2721.     MICRO-C                                                          Page: 57
  2722.  
  2723.  
  2724.              There are cases in which you may  not  want  the  optimizer  to
  2725.           further reduce code substitued for a particular  optimization.  In
  2726.           this case, simply include a single characer comment  in  the  GIVE
  2727.           entry, in such  a  position  as  to  prevent  the  optimizer  from
  2728.           recognizing that with any further TAKE entries.
  2729.     
  2730.              The optimzer also includes a "complement" table, which provides
  2731.           the ability to define and use "opposites" within an  optimization.
  2732.           The most common use for this  feature  is  in  the  processing  of
  2733.           conditional jumps, in cases  when  an  optimization  reverses  the
  2734.           logcal sense of a jump.
  2735.     
  2736.              The complement table is called  "not_table",  and  contains  an
  2737.           even number of character string entries. The table  is  terminated
  2738.           by a single NULL pointer. Each even/odd pair of  entries  in  this
  2739.           table are considered to be complementary strings.  When  a  "give"
  2740.           entry specifies that the complement of a variable string should be
  2741.           output, this table is scanned,  and  if  the  original  string  is
  2742.           found, the corresponding complementary entry is output instead. If
  2743.           the string is not found, it is output without modification.
  2744.     
  2745.              Note that you do not have to access the complementary table  in
  2746.           both the "give" and "take" optimization entries. For example,  you
  2747.           could specify a "special character" of '\221' in the "take" entry,
  2748.           indicating that you are using variable location 1,  and  that  the
  2749.           string must occur in the complement  table.  You  could  then  use
  2750.           "\201" in the "give" entry  to  output  the  original  string,  or
  2751.           "\221" to output the complement.
  2752.     MICRO-C                                                          Page: 58
  2753.  
  2754.  
  2755.     9. THE SOURCE LINKER
  2756.     
  2757.           Many small development environments have assemblers which  do  not
  2758.        directly support an object linker. This causes  a  problem  with  'C'
  2759.        development, because the library functions must be  included  in  the
  2760.        source code, with several drawbacks:
  2761.     
  2762.         1)  There is no way to automatically tell which library functions
  2763.             to include, therefore, you must do it manually.
  2764.     
  2765.         2)  'C' library functions must be  re-compiled every  time,  in
  2766.             order to avoid conflict between compiler generated labels.
  2767.     
  2768.           The MICRO-C Source Linker (SLINK) helps overcome  these  problems,
  2769.        by automatically  joining  previously  compiled  (assembly  language)
  2770.        source code from the library to your programs compiler  output.  Only
  2771.        those files containing  functions  which  you  reference  are  joined
  2772.        (Taking into consideration of course  any  functions  called  by  the
  2773.        included library functions etc...). As the files are joined, compiler
  2774.        generated labels are automatically adjusted to be unique within  each
  2775.        file.
  2776.     
  2777.        9.1 The SLINK Command
  2778.     
  2779.              The format of the SLINK command line is:
  2780.     
  2781.                    SLINK [input_file] [output_file] [options]
  2782.     
  2783.              [input_file] is the name of  the  source  file  containing  the
  2784.           compiler output from your program. If no filenames is given, SLINK
  2785.           will read from standard input.
  2786.     
  2787.              [output_file] is the name of  the  file  to  which  the  linked
  2788.           source code is written. If less  that  two  filenames  are  given,
  2789.           SLINK will write to standard output.
  2790.     
  2791.           9.1.1 Command line options
  2792.     
  2793.                 SLINK accepts the following command line [options]:
  2794.     
  2795.                 ?       - Display command line help summary.
  2796.     
  2797.                 i=name  - Specify name of the External Index File.
  2798.     
  2799.                 -l      - Instructs SLINK to list each library used.
  2800.     
  2801.                 l=path  - Identifies the directory path which will be
  2802.                           taken to reference "library" files. If not
  2803.                           specified, it defaults to: '\mc\slib'
  2804.     
  2805.                 p=char  - Identifies the PREFIX character for compiler
  2806.                           generated symbols. Defaults is '?'.
  2807.     
  2808.                 -q      - Inhibit display of the startup message.
  2809.     
  2810.                 t=string- Prefix to prepend to temporary filenames.
  2811.                           If not specified, default is "$".
  2812.     MICRO-C                                                          Page: 59
  2813.  
  2814.  
  2815.        9.2 The External Index File
  2816.     
  2817.              SLINK uses a special file from the library to  determine  which
  2818.           symbols are in which files. This  files  is  called  the  EXTERNAL
  2819.           INDEX FILE, and is  found  in  the  library  directory  (see  'l='
  2820.           option), under the name "EXTINDEX.LIB".
  2821.     
  2822.              This  file  contains  entries  which  cross-reference  external
  2823.           symbols to files. Each entry is as follows:
  2824.     
  2825.             1)  Any lines beginning with '<' contain the names of files
  2826.                 which are to be processed and included at the BEGINNING
  2827.                 of the program (Before your source file). This the best
  2828.                 way to include the startup code and any runtime library
  2829.                 routines which are required  at  all  times,  and  also
  2830.                 provides a method of initializing any segments used.
  2831.                     eg: <6809rl.asm
  2832.     
  2833.             2)  Any lines beginning with '^' contain the names of files
  2834.                 which are to be processed AFTER the program and library
  2835.                 source files, but BEFORE any  uninitialized  data areas
  2836.                 are output. This is the best way to set up the location
  2837.                 and storage class of the uninitialized data  if it does
  2838.                 not immediately follow the executable program code, and
  2839.                 also providing any postamble needed by the segments.
  2840.     
  2841.             3)  Any lines beginning with '>' contain the names of files
  2842.                 which are to be processed at the END  of  the  program,
  2843.                 after all other information is output. This is the best
  2844.                 way to define heap memory storage,  and  to provide any
  2845.                 post-amble needed by the assembler.
  2846.     
  2847.             4)  Any lines beginning with '-' contain the names of files
  2848.                 which are to  be  included  if  any  of  the  following
  2849.                 symbols  (Up to another '<', '^', '>', '-' or '$')  are
  2850.                 referenced.
  2851.                     eg: -printf.asm format.asm fgets.asm fget.asm
  2852.     
  2853.                 NOTE: In most cases, the library functions will contain
  2854.                 indications of any external references that they do, in
  2855.                 which case SLINK will automatically include those files
  2856.                 even of the names are not mentioned on the '-' line. In
  2857.                 the example above, the following would suffice:
  2858.                         -printf.asm
  2859.     
  2860.             5)  The names  of  each  symbol  which  may  be  referenced
  2861.                 externally must follow the '<', '^', '>' or  '-' entry.
  2862.                 Symbols must occur one per line,  with  no  leading  or
  2863.                 trailing spaces.
  2864.                     eg: printf
  2865.                         fprintf
  2866.                         sprintf
  2867.     MICRO-C                                                          Page: 60
  2868.  
  2869.  
  2870.             6)  A line beginning with '$' is used to define the pseudo-
  2871.                 opcode used by SLINK to reserve uninitialized  data  at
  2872.                 the end of the output file.  Only  one  line  beginning
  2873.                 with '$' should be entered into the EXTINDEX.LIB  file.
  2874.                 The remainder of this line, including all  spaces  etc.
  2875.                 is entered between each symbol name,  and  the  decimal
  2876.                 size (in bytes) which is written to the output file.
  2877.                     eg: '$ RMB '    <- Quotes are for clarity
  2878.     
  2879.             A complete example:
  2880.     
  2881.                     -printf.asm
  2882.                     printf
  2883.                     fprintf
  2884.                     sprintf
  2885.                     -scanf.asm
  2886.                     scanf
  2887.                     fscanf
  2888.                     sscanf
  2889.                     <PREFIX.asm
  2890.                     ^MIDDLE.ASM
  2891.                     >SUFFIX.ASM
  2892.                     $ RMB
  2893.     
  2894.             In summary, the output file is written from:
  2895.     
  2896.                 1 - The '<' (prefix) files              *
  2897.                 2 - The program source files            *\
  2898.                 3 - Library files referenced (if any)   * > See note
  2899.                 4 - Segments 1-9 from above ...         */
  2900.                 5 - The '^' (middle) files
  2901.                 6 - Segments 1-9 from middle files      * See note
  2902.                 7 - Uninitialized data definitions      (if any)
  2903.                 8 - The '>' (suffix) files
  2904.                 9 - Segments 1-9 from sufix file(s)     * See note
  2905.     
  2906.             * NOTE: If these files contain multiple segments (see later),
  2907.                     all segments are grouped and written  in  seguential
  2908.                     order. IE: Seg 0 from all files is written, followed
  2909.                     by Seg 1, etc.
  2910.     
  2911.        9.3 Multiple source files
  2912.     
  2913.              SLINK processes only one source  file,  and  resolves  external
  2914.           references only to the library files. This is because  the  public
  2915.           symbol information is available in the EXTINDEX.LIB  files,  which
  2916.           contains no entries for the user supplied programs.
  2917.     
  2918.              If you wish to use source code  linking  for  a  program  which
  2919.           contains multiple source files, use "#include" statements  at  the
  2920.           end of your main program to include all of the other parts into  a
  2921.           single source file.
  2922.     MICRO-C                                                          Page: 61
  2923.  
  2924.  
  2925.        9.4 Source file information
  2926.     
  2927.           9.4.1 SLINK Directives
  2928.     
  2929.                 SLINK interpretes several "directives" which may be inserted
  2930.              in the  input  source  files  to  control  the  source  linking
  2931.              process. These directives must be on a separate line, beginning
  2932.              in column 1, and must be in  uppercase.  They  are  removed  by
  2933.              SLINK during processing, and thus will not cause conflict  with
  2934.              the normal syntax used by your assembler.
  2935.     
  2936.                                    $SE:<0-9>
  2937.     
  2938.                 The '$SE' directive is used  by  SLINK  to  define  multiple
  2939.              output segments. Up to 10 segments are allowed, with segment  0
  2940.              being the default which  is  selected  when  a  file  is  first
  2941.              encountered.  Other  segments  (1-9)  when  selected  via  this
  2942.              directive are written to temporary files, and re-joined at  the
  2943.              end of processing in  sequential  order.  this  allows  you  to
  2944.              separate sections of the source file (such as initialized data,
  2945.              literal pool etc.) into distinct areas of memory.
  2946.     
  2947.                               $DD:<symbol> <size>
  2948.     
  2949.                 The '$DD' directive is used  to  define  uninitialized  data
  2950.              storage areas, which will be allocated by SLINK between the '^'
  2951.              (middle) and '>' (suffix) files. This allows  you  to  allocate
  2952.              unitialized data outside of the bounds of the executable image,
  2953.              and thus exclude it from being saved to disk. This  action  may
  2954.              be thought  of  as  an  additional  (11'th)  segment  which  is
  2955.              available for uninitialized data only,  and  which  avoids  the
  2956.              temporary file read/write overhead associated with use  of  the
  2957.              other segments. This directive  is  normally  placed  into  the
  2958.              source file by the "def_global" routine  in  the  MICRO-C  code
  2959.              generator.
  2960.     
  2961.                                   $EX:<symbol>
  2962.     
  2963.                 The '$EX' directuve is used by SLINK to identify any symbols
  2964.              which are externally referenced. Whenever a '$EX' directive  is
  2965.              found, SLINK  searches  the  EXTINDX.LIB  file  for  the  named
  2966.              symbol, and marks the corresponding files for inclusion in  the
  2967.              program. This directive is normally placed into the source file
  2968.              by the "def_extern" routine in the MICRO-C code generator.
  2969.     
  2970.                 If you  are  writing  assembly  language  programs  for  the
  2971.              library, be sure to  include  "$SE:<0-9>"  directives  for  any
  2972.              segments you wish to access, "$DD:<symbol>  <size>"  directives
  2973.              for  any  uninitialized  data  you  wish   to   allocate,   and
  2974.              "$EX:<symbol>" directives for any symbols which you  externally
  2975.              reference. If you wish to place an assembly language comment on
  2976.              the same line, make sure it is separated from the remainder  of
  2977.              the directive by at least one space or tab character.
  2978.     MICRO-C                                                          Page: 62
  2979.  
  2980.  
  2981.                 Also, note that '<' (prefix) files may contain "$SE",  "$DD"
  2982.              and "$EX" directives, '^' (middle) files may contain "$SE"  and
  2983.              "$DD" but not "$EX", and '>' (suffix) files may  only  contains
  2984.              "$SE" directives. Basically, the rule is that "$EX"  cannot  be
  2985.              used after the libraries are included and "$DD" cannot be  used
  2986.              after the uninitialized data is output. Since  the  middle  and
  2987.              suffix files  are  ALWAYS  included,  simply  insure  that  all
  2988.              external references and data declarations needed by any of them
  2989.              are performed in the '<' (prefix) file.
  2990.     
  2991.           9.4.2 Compiler generated labels
  2992.     
  2993.                 As it processes each source file, SLINK scans each line  for
  2994.              symbols which consist of the '?' character (See  'p='  option),
  2995.              followed by a number. If it finds such as symbol, it inserts  a
  2996.              two character sequence ranging from 'AA' to  'ZZ'  between  the
  2997.              '?', and the number. This sequence will be incremented for each
  2998.              source file processed,  and  thus  insures  that  the  compiler
  2999.              generated symbols will be unique for each file.
  3000.     
  3001.                 If you  are  writing  assembly  language  programs  for  the
  3002.              library, you must be careful to  avoid  using  identical  local
  3003.              symbols in any of the library files, one way to do this  is  to
  3004.              use symbols which meet the above criteria.
  3005.     
  3006.        9.5 The SCONVERT command
  3007.     
  3008.              SCONVERT is a utility  which  assists  in  converting  existing
  3009.           assembly language  source  files  into  a  format  which  is  more
  3010.           suitable for use by the SLINK. Two main functions are performed:
  3011.     
  3012.           1) All comments are removed, and  all  spacing  is  reduced  to  a
  3013.              single space. This minimizes the size of the  file,  and  helps
  3014.              decrease linkage time.
  3015.     
  3016.           2) All symbols defined in the file which  are  not  identified  as
  3017.              "keep" symbols are converted to resemble the  MICRO-C  compiler
  3018.              generated symbols. This allows  SLINK  to  adjust  them  to  be
  3019.              unique within each source file.
  3020.     
  3021.              The format of the SCONVERT command line is:
  3022.     
  3023.     
  3024.                  SCONVERT [input_file] [output_file] [options]
  3025.     
  3026.              [input_file] is the name of  the  source  file  containing  the
  3027.           original assembly language program.  If  no  filenames  is  given,
  3028.           SCONVERT will read from standard input.
  3029.     
  3030.              [output_file] is the name of the file to  which  the  converted
  3031.           source code is written. If less  that  two  filenames  are  given,
  3032.           SCONVERT will write to standard output.
  3033.     MICRO-C                                                          Page: 63
  3034.  
  3035.  
  3036.           9.5.1 Command line options
  3037.     
  3038.                 SCONVERT accepts the following command line [options]:
  3039.     
  3040.                 ?       - Display command line help summary.
  3041.     
  3042.                 c=char  - Identifies the character used to begin a comment
  3043.                           at the trailing end of a source line. If no 'c='
  3044.                           is defined, SCONVERT will terminate processing at
  3045.                           the first blank or tab which follows the operand
  3046.                           field.
  3047.     
  3048.                 C=char  - Identifies the charcter which indicates a comment
  3049.                           line in the source code. Defaults to '*'.
  3050.     
  3051.                 k=name  - Identifies a symbol name to KEEP. This symbol will
  3052.                           not be converted. Multiple 'k=' are permitted.
  3053.     
  3054.                 K=file  - Identifies a file containing the names of symbols
  3055.                           to KEEP, one per line. Multiple 'K=' are permitted.
  3056.     
  3057.                 p=char  - Identifies the PREFIX character which is to be used
  3058.                           for the converted symbols. Defaults to '?'.
  3059.     
  3060.                 -q      - Instructs SCONVERT to be quiet, and not issue its
  3061.                           startup message.
  3062.     
  3063.                 SCONVERT identifies symbols in the input source file as  any
  3064.              string beginning with 'A-Z', 'a-z', '_' or '?', and  containing
  3065.              these charcters plus the digits '0-9'. If your assembler source
  3066.              files uses any other characters in its symbols, you  must  edit
  3067.              your sources and change the symbols.
  3068.     
  3069.        9.6 The SRENUM command
  3070.     
  3071.              SRENUM  is  a  small  utility  which  re-numbers  the  compiler
  3072.           generated symbols within a assembly language source file. This  is
  3073.           useful if you have made added symbols to the  file  by  hand,  and
  3074.           wish to make it "pretty" before adding it to the library etc.
  3075.     
  3076.              The format of the SRENUM command is:
  3077.     
  3078.                   SRENUM [input_file] [output_file] [options]
  3079.     
  3080.           9.6.1 Command line options
  3081.     
  3082.                 SRENUM accepts the following command line [options]:
  3083.     
  3084.                 ?       - Display command line help summary.
  3085.     
  3086.                 p=char  - Identifies the PREFIX character which is to be used
  3087.                           to recognize compiler generated symbols.
  3088.     
  3089.                 -q      - Instructs SRENUM to be quiet, and not issue its
  3090.                           startup message.
  3091.     MICRO-C                                                          Page: 64
  3092.  
  3093.  
  3094.        9.7 The SINDEX command
  3095.     
  3096.              SINDEX is a utility  which  assists  in  the  creation  of  the
  3097.           EXTINDEX.LIB file used by SLINK. When you run SINDEX, it  examines
  3098.           all of the '.ASM' files in the current  directory,  and  writes  a
  3099.           EXTINDEX.LIB file which contains a '-' type entry for  each  file,
  3100.           and  external  symbol  entries  for  any  labels  which  it  finds
  3101.           conforming to the 'C' naming conventions (Starts with 'a-z', 'A-Z'
  3102.           or '_', and contains only 'a-z', 'A-Z', '0-9' or '_').
  3103.     
  3104.              Once  you  have  run  SINDEX,  you  must  manually   edit   the
  3105.           EXTINDEX.LIB file, and remove any file or symbol entries which you
  3106.           do not wish to have available as external references, as  well  as
  3107.           insert any necessary entries for '<', '^', '>' and '$' commands.
  3108.     
  3109.           9.7.1 Command line options
  3110.     
  3111.                 SINDEX accepts the following command line options:
  3112.     
  3113.                 ?       - Display command line help summary.
  3114.     
  3115.                 i=name  - Specify name for index file to be written.
  3116.                           Dafault is "EXTINDEX.LIB".
  3117.     
  3118.                 You may also instruct SINDEX to search for  a  file  pattern
  3119.              other than '*.ASM' by passing it as a command line parameter.
  3120.     
  3121.                                 eg: SINDEX *.A86
  3122.     
  3123.        9.8 The SLIB command
  3124.     
  3125.              Once you have constructed your source  library,  you  may  from
  3126.           time to time want to make minor changes to it, either  adding  new
  3127.           functions, or removing old ones ones.
  3128.     
  3129.              You could make such changes simply by editing the  EXTINDEX.LIB
  3130.           file, however you would have to be very  careful  not  to  add  or
  3131.           delete the wrong entry, and you would have to  manually  determine
  3132.           if adding or removing the file would adversly affect the remainder
  3133.           of the library. For example, you could accidently add a  duplicate
  3134.           of another symbol name, or remove a symbol which is referred to by
  3135.           another file.
  3136.     
  3137.              To simplify maintenance of source libraries, you can  make  use
  3138.           of the "Source Librarian", a utility program which  automates  the
  3139.           addition and removal of source files, and automatically reports of
  3140.           any inconsistancies occuring in the source library.
  3141.     
  3142.              To use SLIB, you must first position yourself to the  directory
  3143.           containing the source library. And then  execute  SLIB  using  the
  3144.           command options described later to indicate the action to be taken
  3145.           on the library. If you do  not  specify  any  actions,  SLIB  will
  3146.           simply examine the library and report its size and content.
  3147.     MICRO-C                                                          Page: 65
  3148.  
  3149.  
  3150.              You may use multiple command options in a single  SLIB  command
  3151.           if you wish to add and/or remove more than one file at a time.
  3152.     
  3153.              After  executing  any  command,  SLIB  will   report   on   any
  3154.           inconsistancies which it finds in the library. If any  are  found,
  3155.           and you have used a command which caused changes, SLIB will prompt
  3156.           for permission before writing the updated library file.
  3157.     
  3158.           9.8.1 Command line options
  3159.     
  3160.                 The following options control the action(s)  which  will  be
  3161.              performed by SLIB on the source library index file.
  3162.     
  3163.                 ?       - Display command line help summary.
  3164.     
  3165.                 ?=file  - Display information about named source file.
  3166.     
  3167.                 a=file  - Add specified file as standard functions.
  3168.     
  3169.                 i=index - Use the specified INDEX file, if not specified,
  3170.                           the filename 'EXTINDEX.LIB' is assumed.
  3171.     
  3172.                 m=file  - Add named source file as a MIDDLE file.
  3173.     
  3174.                 p=file  - Add named source file as a PREFIX file.
  3175.     
  3176.                 -q      - Quiet mode: SLIB will not display informational
  3177.                           messages or ask for permission to update index.
  3178.     
  3179.                 r=file  - Remove the named file from the index.
  3180.     
  3181.                 s=file  - Add named source file as a SUFFIX file.
  3182.     
  3183.                 -w      - Write inhibit:  SLIB will not write the updated
  3184.                           library index.  This is useful if you just want
  3185.                           to see what would happen if you add or remove a
  3186.                           file.
  3187.     MICRO-C                                                          Page: 66
  3188.  
  3189.  
  3190.        9.9 Making a source library
  3191.     
  3192.              To make a complete source linkable library, follow these  basic
  3193.           steps:
  3194.     
  3195.           1) If you have assembly language library functions, run the SINDEX
  3196.              utility to create an index file with the names of  any  symbols
  3197.              defined in them. Edit this file and remove all names which  are
  3198.              LOCAL to the files. Only the global function and variable names
  3199.              should remain. NOTE: Also leave in any other symbols  or  names
  3200.              which you don't want changed by SCONVERT.
  3201.     
  3202.           2) Use SCONVERT to convert  the  assembly  language  sources  into
  3203.              library format, using the index file created above as your KEEP
  3204.              file (K=EXTINDEX.LIB). You may send the output  files  directly
  3205.              to your source library directory.
  3206.     
  3207.           3) Edit the converted assembly  language  sources  to  change  any
  3208.              declarations for uninitialized data into '$DD' directives,  and
  3209.              to add any '$SE' and '$EX' directives which may be needed.
  3210.     
  3211.           4) Compile all of your 'C' library functions to assembly language,
  3212.              using a code generator which outputs the appropriate directives
  3213.              for SLINK. Send the ASM output files  to  your  source  library
  3214.              directory.
  3215.     
  3216.           5) From within your library  directory,  run  the  SINDEX  utility
  3217.              again. This will create  an  index  file  (EXTINDEX.LIB)  which
  3218.              contains the names of all global symbols.
  3219.     
  3220.           6) Edit the index file and remove any non-public symbol names. You
  3221.              should also change the headers for the '<', '^' and '>'  files,
  3222.              and add the '$' record for reserved memory information.
  3223.     
  3224.           7) Run the SLIB utility, to check the new  library  for  duplicate
  3225.              symbols,  unresolved  external   references   and   any   other
  3226.              inconsistancies.
  3227.     MICRO-C                                                          Page: 67
  3228.  
  3229.  
  3230.     10. THE MAKE UTILITY
  3231.     
  3232.           The MAKE utility provides a method of automating the  building  of
  3233.        larger programs consisting of more that one module. The main  benefit
  3234.        of MAKE is that it keeps track of  the  files  that  each  module  is
  3235.        dependant on, and will rebuild a module if any of  those  files  have
  3236.        been modified since  the  module  was  last  built.  This  frees  the
  3237.        programmer from  the  task  of  remembering  which  files  have  been
  3238.        changed, and the commands needed to rebuild the dependant modules.
  3239.     
  3240.        10.1 MAKEfiles
  3241.     
  3242.              To use MAKE, you must first create a MAKEFILE, which is a  text
  3243.           file containing entries for each module in the program. Each entry
  3244.           consists of a DEPENDANCY list, and a series of COMMANDS.
  3245.     
  3246.           10.1.1 MAKEfile Entries
  3247.     
  3248.                 A dependency list in MAKE is a line which contains the  name
  3249.              of the module, followed by a ':', followed by the names of  any
  3250.              files on which it depends. The module name MUST begin in column
  3251.              1.
  3252.     
  3253.                 When MAKE is invoked, it will process each dependancy  list,
  3254.              and  will  execute  any  following  commands  (up  to   another
  3255.              dependancy list) if (1) the module does not exist,  or  (2)  if
  3256.              any of the files to the right of the ':' have a timestamp which
  3257.              is later than that of the module. For example:
  3258.     
  3259.                 main.obj : main.c main.h \\mc\\stdio.h
  3260.                     \\mc\\mcc main.c main.asm
  3261.                     masm/ml main;
  3262.                     -del main.asm
  3263.     
  3264.                 In the above example, the  'main.obj'would  be  rebuilt  (by
  3265.              compiling and assembling 'main.c') if either it did not already
  3266.              exist, or any of 'main.c', 'main.h' or '\mc\stdio.h' was  found
  3267.              to have a later timestamp.
  3268.     
  3269.                 The '-' preceeding the 'del' command prevents it from  being
  3270.              displayed. Unless the '-q' option is enabled, MAKE will display
  3271.              any commands not preceeded by '-' as they are executed.
  3272.     
  3273.                 NOTE: To enter a single '\' in the MAKEFILE,  you  must  use
  3274.              '\\', this is because like 'C',  MAKE  uses  '\'  to  "protect"
  3275.              special  characters  which  otherwise  are  used  for   special
  3276.              functions (such as '\', '$' and '#'). The first '\'  "protects"
  3277.              the second one, allowing it to pass through as source text.
  3278.     MICRO-C                                                          Page: 68
  3279.  
  3280.  
  3281.           10.1.2 Macro Substitutions
  3282.     
  3283.                 Sometimes in a MAKEFILE, you have a single file or directory
  3284.              path that you use  over  and  over  again.  If  it  is  a  long
  3285.              directory path, this may  involve  a  lot  of  typing,  and  it
  3286.              becomes inconvenient to change that name (if you want to use  a
  3287.              different directory etc.) because it is repeated many times.
  3288.     
  3289.                 MAKE includes a MACRO facility, which allows you  to  define
  3290.              variable names which will be replaced with a text  string  when
  3291.              used in subsequent MAKEfile lines. Names are defined by placing
  3292.              them in the MAKEfile, followed by '=',  and  the  text  string.
  3293.              Macro names being defined MUST begin in  column  one,  and  may
  3294.              consist of the characters ('a'-'z', 'A'-'Z', '0'-'9', and '_').
  3295.     
  3296.                 Whenever MAKE encounters a '$' in the  file,  it  takes  the
  3297.              name immediately following, and performs the macro replacement:
  3298.     
  3299.                 mcdir = \\mc
  3300.                 main.obj : main.c main.h $mcdir\\stdio.h
  3301.                     $mcdir\\mcc main.c main.asm
  3302.                     masm/ml main;
  3303.                     del main.asm
  3304.     
  3305.     
  3306.                 When a macro name is immediately  followed  by  alphanumeric
  3307.              text, use a single '\' to  separate  it  from  the  text.  This
  3308.              "protects"  the  first  character  of  the  text   from   being
  3309.              interpreted as part of the macro name:
  3310.     
  3311.                 mcdir = \\mc\\
  3312.                 main.obj : main.c main.h $mcdir\stdio.h
  3313.                     $mcdir\mcc main.c main.asm
  3314.                     masm/ml main;
  3315.                     del main.asm
  3316.     
  3317.                 There  are  several  predefined  macro  symbols  which   are
  3318.              available:
  3319.     
  3320.     
  3321.                 $*      = The full name of the dependant module (name.type).
  3322.                 $@      = The name only of the dependant module.
  3323.                 $.      = The full name of each file in the dependancy list,
  3324.                           separated from each other by a single space.
  3325.                 $,      = The full name of each file in the dependancy list,
  3326.                           separated from each other by a single comma.
  3327.                 $:      = The name only of each file in the dependancy list,
  3328.                           separated from each other by a single space.
  3329.                 $;      = The name only of each file in the dependancy list,
  3330.                           separated from each other by a single comma.
  3331.     MICRO-C                                                          Page: 69
  3332.  
  3333.  
  3334.                 File names in the dependancy list which are preceeded by '-'
  3335.              will not be included in the '$. $, $: $;' macro expansions:
  3336.     
  3337.                 mcdir = \\mc
  3338.                 main.obj : main.c -main.h -$mcdir\\stdio.h
  3339.                     $mcdir\\mcc $. $@.ASM
  3340.                     masm/ml $@;
  3341.                     del $@.ASM
  3342.     
  3343.           10.1.3 MAKEfile Comments
  3344.     
  3345.                 Whenever MAKE encounters the '#' character in the  MAKEFILE,
  3346.              it treats the remainder of the line as a comment, and does  not
  3347.              process it:
  3348.     
  3349.                 # Define Directories
  3350.                 mcdir = \\mc
  3351.     
  3352.                 # Build the MAIN module
  3353.                 main.obj : main.c -main.h -$mcdir\\stdio.h  # Dependants
  3354.                     $mcdir\\mcc $. $@.ASM                   # Compile
  3355.                     masm/ml $@;                             # Assemble
  3356.                     del $@.ASM                              # Delete tmp
  3357.     
  3358.           10.1.4 Ordering the MAKEfile
  3359.     
  3360.                 MAKE processes the MAKEfile is sequential fashion, with  the
  3361.              entries near the top being processed before  the  entries  near
  3362.              the bottom. To insure that each module is built  properly,  any
  3363.              files appearing in the dependancy list for a module  which  are
  3364.              themselves dependant  on  other  files,  should  have  MAKEfile
  3365.              entries which occur BEFORE the entries for  the  modules  which
  3366.              are dependant on them:
  3367.     
  3368.                 # Define Directories
  3369.                 mcdir = \\mc
  3370.                 # Build the MAIN module
  3371.                 main.obj : main.c -main.h -$mcdir\\stdio.h
  3372.                     $mcdir\\mcc $. $@.ASM
  3373.                     masm/ml $@;
  3374.                     del $@.ASM
  3375.                 # Build the SUB module
  3376.                 sub.obj : sub.c -sub.h
  3377.                     $mcdir\\mcc $. $@.ASM
  3378.                     masm/ml $@;
  3379.                     del $@.ASM
  3380.                 # Bind the executable file
  3381.                 # NOTE: If either of the above modules is rebuilt,
  3382.                 #       this entry will be guarenteed to execute.
  3383.                 main.exe : main.obj sub.obj
  3384.                     LINK $:;
  3385.     MICRO-C                                                          Page: 70
  3386.  
  3387.  
  3388.        10.2 Directives
  3389.     
  3390.              Like 'C', MAKE recognizes several "directives" in the MAKEfile.
  3391.           These  directives  are  only  recognized  if  they  occur  at  the
  3392.           beginning of the input line:
  3393.     
  3394.           10.2.1 @include <filename>
  3395.     
  3396.                 This command causes the indicated file to be opened and read
  3397.              in as the source  text.  When  the  end  of  the  new  file  is
  3398.              encountered, processing will continue with the  line  following
  3399.              "@include" in the original MAKEfile.
  3400.     
  3401.           10.2.2 @ifdef <name>
  3402.     
  3403.                 Processes the following lines (up to @else of  @endif)  only
  3404.              if the given MACRO name is defined. NOTE: <name> should not  be
  3405.              preceeded by '$', otherwise its CONTENTS will be tested.
  3406.     
  3407.           10.2.3 @ifndef <name>
  3408.     
  3409.                 Processes the following lines (up to @else of  @endif)  only
  3410.              if the given MACRO name is NOT defined.
  3411.     
  3412.           10.2.4 @ifeq <word1> <word2>
  3413.     
  3414.                 Processes the following lines (up to @else of  @endif)  only
  3415.              if the following two words match exactly. This  is  useful  for
  3416.              testing the value of a defined MACRO symbol.
  3417.     
  3418.           10.2.5 @ifne <word1> <word2>
  3419.     
  3420.                 Processes the following lines (up to @else or  @endif)  only
  3421.              if the following two words do not match.
  3422.     
  3423.           10.2.6 @else
  3424.     
  3425.                 Processes the following lines (up to  @endif)  only  if  the
  3426.              preceeding @ifdef, @ifndef, @ifeq or @ifne was false.
  3427.     
  3428.           10.2.7 @endif
  3429.     
  3430.                 Terminates @ifdef, @ifndef, @ifeq and @ifne.
  3431.     
  3432.           10.2.8 @type <text>
  3433.     
  3434.                 Displays the following text.
  3435.     
  3436.           10.2.9 @abort [text]
  3437.     
  3438.                 Terminates MAKE with an 'Aborted!' message. Any text on  the
  3439.              remainder of the line will be appended to the message.
  3440.     MICRO-C                                                          Page: 71
  3441.  
  3442.  
  3443.        10.3 The MAKE command
  3444.     
  3445.              The format of the MAKE command line is:
  3446.     
  3447.                            MAKE [makefile] [options]
  3448.     
  3449.              [makefile] is the name of the MAKEfile to process. If  no  name
  3450.           is given, MAKE assumes the default name 'MAKEFILE'.
  3451.     
  3452.           10.3.1 Command Line Options
  3453.     
  3454.                 MAKE accepts the following command line [options]:
  3455.     
  3456.                 ?       - Causes MAKE to output a short summary  of  the
  3457.                           available command line options.
  3458.     
  3459.                 -d      - Instructs MAKE to operate in "debug" mode, and
  3460.                           display the commands which it  would  execute,
  3461.                           without actually executing them. This provides
  3462.                           a method of quickly testing the MAKEFILE.
  3463.     
  3464.                 -q      - Instructs MAKE to be quiet, and not display the
  3465.                           informational messages and commands executed as
  3466.                           it progresses.
  3467.     
  3468.         <name>=<text>   - Pre-defines a macro  of  the  specified  <name>
  3469.                           with the string value  <text>.  This  OVERRIDES
  3470.                           any definition within the MAKEfile,  which  may
  3471.                           be used to establish a "default" value.
  3472.     MICRO-C                                                          Page: 72
  3473.  
  3474.  
  3475.        10.4 The TOUCH command
  3476.     
  3477.              TOUCH is a small utility program which sets  the  timestamp  of
  3478.           one or more files to the current or  specified  time/date.  It  is
  3479.           useful as a  method  of  forcing  MAKE  to  recognize  a  file  as
  3480.           "changed", even when it has not.
  3481.     
  3482.              For example, if  you  had  decided  to  "undo"  several  recent
  3483.           changes by restoring a backup of 'main.c', the restored file  will
  3484.           probably have a timestamp which is  older  than  the  last  module
  3485.           which was built. In this case, MAKE would be unaware that the file
  3486.           has changed, and would therefore not rebuild the module.
  3487.     
  3488.              The TOUCH command could then be used to "update" the  timestamp
  3489.           of 'main.c' to the current time, causing MAKE to recognize it as a
  3490.           changed file.
  3491.     
  3492.                                   TOUCH main.c
  3493.     
  3494.              You could also use TOUCH to force rebuilding of several files:
  3495.     
  3496.                            TOUCH main.c sub1.c sub2.c
  3497.     
  3498.              Or even ALL '.C' files:
  3499.     
  3500.                                    TOUCH *.c
  3501.     
  3502.              TOUCH can also be used to set the timestamp of  a  file  to  an
  3503.           arbritrary value, this may be useful  to  PREVENT  a  change  from
  3504.           causing an update:
  3505.     
  3506.                          TOUCH main.c t=0:00 d=31/10/80
  3507.     
  3508.              NOTE: Use of the 't=' or 'd=' parameters to  TOUCH  allows  the
  3509.           possibility that a changed file  will  go  unnoticed.  CAUTION  is
  3510.           advised.
  3511.     
  3512.              The MSDOS  implementation  of  TOUCH  supports  '-h'  and  '-s'
  3513.           options, which cause it to set  the  timestamp  of  HIDDEN  and/or
  3514.           SYSTEM files. If these options are not used, TOUCH will not affect
  3515.           those types of files.
  3516.  
  3517.  
  3518.  
  3519.                                     MICRO-C
  3520.  
  3521.                                TABLE OF CONTENTS
  3522.  
  3523.  
  3524.                                                                          Page
  3525.  
  3526.      1. INTRODUCTION                                                        1
  3527.  
  3528.         1.1 Compiler Portability                                            2
  3529.         1.2 Code Portability                                                2
  3530.         1.3 The compiling process                                           3
  3531.  
  3532.      2. THE COMMAND CO-ORDINATOR                                            4
  3533.  
  3534.         2.1 The CC command                                                  4
  3535.         2.2 Using multiple object modules                                   6
  3536.  
  3537.      3. THE MICRO-C PROGRAMMING LANGUAGE                                    7
  3538.  
  3539.         3.1 Constants                                                       7
  3540.         3.2 Symbols                                                         7
  3541.         3.3 Arrays & Pointers                                              11
  3542.         3.4 Functions                                                      11
  3543.         3.5 Structures & Unions                                            12
  3544.         3.6 Control Statements                                             15
  3545.         3.7 Expression Operators                                           17
  3546.         3.8 Inline Assembly Language                                       19
  3547.         3.9 Preprocessor Commands                                          20
  3548.         3.10 Error Messages                                                21
  3549.         3.11 Quirks                                                        26
  3550.  
  3551.      4. ADVANCED TOPICS                                                    30
  3552.  
  3553.         4.1 Conversion Rules                                               30
  3554.         4.2 Assembly Language Interface                                    31
  3555.         4.3 Compiling for ROM                                              34
  3556.  
  3557.      5. THE MICRO-C COMPILER                                               35
  3558.  
  3559.         5.1 The MCC command                                                35
  3560.  
  3561.      6. PORTING THE COMPILER                                               36
  3562.  
  3563.         6.1 The "io" module                                                36
  3564.         6.2 The "code" module                                              38
  3565.         6.3 The "compile" module                                           44
  3566.         6.4 Porting without a linker                                       45
  3567.         6.5 Optimization Techniques                                        45
  3568.  
  3569.      7. THE MICRO-C PREPROCESSOR                                           48
  3570.  
  3571.         7.1 The MCP command                                                49
  3572.         7.2 Preprocesor Commands                                           50
  3573.  
  3574.     MICRO-C                                                Table of Contents
  3575.  
  3576.                                                                          Page
  3577.         7.3 Error messages                                                 53
  3578.  
  3579.      8. THE MICRO-C OPTIMIZER                                              55
  3580.  
  3581.         8.1 The MCO command                                                55
  3582.         8.2 Porting MCO to a new processor                                 56
  3583.  
  3584.      9. THE SOURCE LINKER                                                  58
  3585.  
  3586.         9.1 The SLINK Command                                              58
  3587.         9.2 The External Index File                                        59
  3588.         9.3 Multiple source files                                          60
  3589.         9.4 Source file information                                        61
  3590.         9.5 The SCONVERT command                                           62
  3591.         9.6 The SRENUM command                                             63
  3592.         9.7 The SINDEX command                                             64
  3593.         9.8 The SLIB command                                               64
  3594.         9.9 Making a source library                                        66
  3595.  
  3596.      10. THE MAKE UTILITY                                                  67
  3597.  
  3598.         10.1 MAKEfiles                                                     67
  3599.         10.2 Directives                                                    70
  3600.         10.3 The MAKE command                                              71
  3601.         10.4 The TOUCH command                                             72
  3602.